我正在使用 react-router 版本 4,因为组件的路由配置已完成,但组件没有挂载,因为我尝试使用 componentDidMount(( 方法,控制台日志没有显示。
这是我的代码,
import { Route,Switch,hashHistory } from 'react-router';
import {HashRouter as Router} from 'react-router-dom';
import { createHistory, useBeforeUnload } from 'history';
<Router history={hashHistory}>
<div>
<Route exact path='/userlogin/' component={LoginPage}></Route>
<Route exact path='/dashboard/' component={Dashboard}></Route>
<Route exact path='/forgotpassword/' component={ForgotPasswordPage}></Route>
</div>
</Router>
由于当我尝试使用组件的路由器 url 路径时页面为空。
任何帮助,不胜感激。提前感谢。!
我的路线如下所示:
var routes = (
<Router history={browserHistory}>
<Route path='/' component={Main}>
<IndexRoute component={Home} />
<Route path='chapters' component={ChapterListContainer} />
<Route path='chapters/chapter:id' component={ChapterPageContainer}></Route>
</Route>
</Router>
);
有几个区别:
- 路线周围没有
<div>
,它们用path='/'
指示根组件 - 我还有一个索引路由,它告诉路由器默认情况下应该显示哪个组件