路由如下:
<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>