亲爱的,这是主要组件,我在其中导入了其他组件并制作了Route对象,Links在起作用,历史对象也发生了变化,但是组件未呈现(在此我不使用redux)。控制台也不会出现任何错误
import React from 'react';
import {BrowserRouter as Router,Route,Link} from 'react-router-dom';
import Main from './components/Main';
import Dashboard from './components/Dashboard';
import Login from './components/Login';
import Register from './components/Register';
class App extends React.Component {
render() {
return (
<Router>
<div className='container'>
<ul>
<li>
<Link to="/">Main</Link>
</li>
<li>
<Link to="/register">Register</Link>
</li>
<li>
<Link to="/login">Login</Link>
</li>
</ul>
<Route path="/" Component={Main}/>
<Route path="/login" Component={Login}/>
<Route path="/register" Component={Register}/>
<Route path="/dashboard" Component={Dashboard}/>
</div>
</Router>
)
}
}
export default App;
答案 0 :(得分:2)
尝试将Component
小写,如下所示:
<Route path="/" component={Main}/>
<Route path="/login" component={Login}/>
<Route path="/register" component={Register}/>
<Route path="/dashboard" component={Dashboard}/>