在哪里指定应用程序的reacjs-router入口点

时间:2017-04-05 10:49:53

标签: reactjs react-router

在我的反应应用程序中,我希望入口点不是localhost:3000 /

它应该是localhost:3000 / dashboard

我可以在哪里设置?

谢谢,我现在已经这样做了,因为我的路线是在路线文件中

{
    path: '/',
    exact: true,
    sidebar: () => <div>home!</div>,
    main: () => <Dashboard />
},

我也可以为此链接指定activeClassName吗?

3 个答案:

答案 0 :(得分:1)

为它设置IndexRoute。

<IndexRoute component={Dashobard} />

一个很好的例子是:

 <Router history={hashHistory}>
    <Route path='/' component={Container}>
      <IndexRoute component={Home} />
      <Route path='/address' component={Address} />
      <Route path='*' component={NotFound} />
    </Route>
  </Router>

当您点击http://localhost:3000时,Home组件将呈现

答案 1 :(得分:1)

您的路由器配置应与此类似:

<Router history={history}>
    <Route path="/" component={App}>
        <IndexRoute component={Dashboard}/>
    </Route>
</Router>

答案 2 :(得分:0)

我想你想在webpack-dev-server上设置,所以在webpack.config.js中你应该设置publicPath

publicPath: "/dashboard",