0

我正在使用 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 路径时,页面为空。

任何帮助表示赞赏。在此先感谢。!

4

1 回答 1

1

我的路线如下所示:

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>
);

有几个区别:

  1. 路由周围没有<div>,它们用a封装 path='/'以指示根组件
  2. 我还有一个索引路由,它告诉路由器默认情况下应该显示哪个组件
于 2017-04-11T09:13:17.340 回答