如果没有传递参数则默认为主路由

Default to home route if no param passed

我在 index.js

上设置了一些基本路线
import { Router,
  Route,
  hashHistory,
  Link } from 'react-router';

ReactDOM.render(
               <Router history={hashHistory}>
                <Route path="/" component={Users} />
                <Route path="/posts/:id" component={Posts} />
              </Router>
            ,
document.getElementById('root')

如果帖子路由没有传递参数,我可以重定向到主页路由吗?

您可以为该路线添加 <Redirect>

<Router history={ hashHistory }>
  <Route path="/" component={ Users } />
  <Redirect from="/posts/" to="/" />
  <Route path="/posts/:id" component={ Posts } />
</Router>