首页 > react-router如何区分同级而不同参数的路由?

react-router如何区分同级而不同参数的路由?

路由如下:

<Router history={history}>
    <Route path="/" component={App}>
        <IndexRoute component={Home} />
        <Route path=":category" component={Category} />
        <Route path=":postId.html" component={Post} />
        <Route path="*" component={NotFound} />
    </Route>
</ROuter>

这种情况怎么办呢?所有路由都被:category截掉了,进不了:postId.html路由。


虽然我没怎么用过react-router,但也觉得你这样不OK。路由的配置重了,为了去重,最简单的方式就是加前缀:

<Router history={history}>
    <Route path="/" component={App}>
        <IndexRoute component={Home} />
        <Route path="category/:category" component={Category} />
        <Route path="post/:postId" component={Post} />
        <Route path="*" component={NotFound} />
    </Route>
</ROuter>
【热门文章】
【热门文章】