Reactjs 如何设置路由的默认参数?

Reactjs 如何设置路由的默认参数?,reactjs,react-router,Reactjs,React Router,以下是我的路线定义: export default <Route> <Route path='account/login' component={Login}/> <Route component={ Layout }> <Route path='/' components={{ body: Home, bar: NavBar }} /> <Route path='/entry' compone

以下是我的路线定义:

export default <Route>
    <Route path='account/login' component={Login}/>
    <Route component={ Layout }>
        <Route path='/' components={{ body: Home, bar: NavBar }} />
        <Route path='/entry' components={{ body: Entry, bar: NavBar }}>
            <Route path='(:weekStartDate)'/>
        </Route>
    </Route>
</Route>;
导出默认值
;
我想实现的是,如果用户转到“mysite.com/entry”,他应该被重定向到“mysite.com/entry/12-09-2016”。为什么这么难?我找不到任何资源来实现这一目标。你能帮我解决这个问题吗

反应版本:15.0.1
react路由器版本:2.1.1

几个月前,我遇到了类似的问题。我发现唯一合适的解决方案是服务器端重定向

几个月前我也有类似的问题。我发现唯一合适的解决方案是服务器端重定向

对路由使用onEnter函数,检查参数是否已设置,否则默认设置

function defaultParam(nextState, replace) {
  if (!nextState.params.weekStartDate) {
    replace('/entry/12-09-2016')
  }
}

...
<Route path='entry/:weekStartDate' onEnter={defaultParam} components={{ body: Entry, bar: NavBar }}/>
函数defaultParam(下一状态,替换){
如果(!nextState.params.weekStartDate){
替换(“/entry/12-09-2016”)
}
}
...

对路由使用onEnter功能,检查参数是否已设置,否则默认设置

function defaultParam(nextState, replace) {
  if (!nextState.params.weekStartDate) {
    replace('/entry/12-09-2016')
  }
}

...
<Route path='entry/:weekStartDate' onEnter={defaultParam} components={{ body: Entry, bar: NavBar }}/>
函数defaultParam(下一状态,替换){
如果(!nextState.params.weekStartDate){
替换(“/entry/12-09-2016”)
}
}
...

不应该这样。这真令人沮丧!不应该是这样。这真令人沮丧!