【发布时间】:2017-05-04 03:14:51
【问题描述】:
我正在使用 react-router v3.0.0 和 react v15.1.0。我有以下路线设置:
ReactDom.render(<Provider store={store}>
<Router history={BrowserHistory}>
<Route path='shop' component={App}>
<IndexRoute component={Shop} />
<Route path='/product' component={ProductView} />
</Route>
</Router>
</Provider>, document.getElementById('app'));
如您所见,我的应用程序基础Route 的路径为'shop'。就用户而言,这应该导致 2 个单独的路由,http://example.com/shop 和 http://example.com/shop/product。然而,这种情况并非如此。
当我部署上述代码时,http://example.com/shop 正确呈现,但 http://example.com/shop/product 没有呈现任何内容。事实上,我得到一个控制台错误:
Warning: [react-router] Location "/shop/product" did not match any routes
所以,我稍微改变了我的设置:
ReactDom.render(<Provider store={store}>
<Router history={BrowserHistory}>
<Route path='shop/' component={App}>
<IndexRoute component={Shop} />
<Route path='product' component={ProductView} />
</Route>
</Router>
</Provider>, document.getElementById('app'));
这将允许我渲染http://example.com/shop/(注意尾部正斜杠)、http://example.com/shop/product、但不是http://example.com/shop。
是否可以在同一个应用中呈现http://example.com/shop、http://example.com/shop/、http://example.com/shop/product?
【问题讨论】:
-
/shop/和/shop意思相同,因此无法区分。但/shop/product与那些不同,可以区分。
标签: javascript reactjs react-router jsx