反应路由器链接更改URL,但不查看

时间:2019-11-19 15:51:04

标签: javascript reactjs

我有一个App.js,看起来像这样:

import React, { Component } from 'react';
import './App.css';
import PdfViewer from './components/PdfViewer';
import {BrowserRouter as Router, Link, Switch, Route} from 'react-router-dom'
import history from './history';
import Homepage from './components/Homepage'
class App extends Component {
  render() {
    return (
      <Router history={history}>
      <Switch>
      <Route exact path="/" component={Homepage} />
      <Route path="/pdfviewer" component={PdfViewer} />
      </Switch>      
      </Router>
    );
  }
}

在嵌套组件内部,我有一个<Link>像这样:

import React from 'react';
import ListItem from '@material-ui/core/ListItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import DashboardIcon from '@material-ui/icons/Dashboard';

import { BrowserRouter as Router, Link } from "react-router-dom";

export const MainListItems = () => {
  return(
  <Link to="/">
  <div>
    <ListItem button>
      <ListItemIcon>
        <DashboardIcon />
      </ListItemIcon>
      <ListItemText primary="Dashboard" />
    </ListItem>

  </div>
  </Link>
  )}

这是我的呈现链接的组件。 单击后,Url会更改,但不会呈现新组件……怎么了?

0 个答案:

没有答案