【发布时间】:2016-09-22 13:28:15
【问题描述】:
我们该怎么做?特别是当路径的一部分是参数(:someParam)时。我在文档中找不到任何内容。
【问题讨论】:
-
你能解释清楚一点吗?举个例子。
标签: reactjs react-router
我们该怎么做?特别是当路径的一部分是参数(:someParam)时。我在文档中找不到任何内容。
【问题讨论】:
标签: reactjs react-router
现在建议在这种情况下使用 react-router 3 https://github.com/ReactTraining/react-router/issues/3325
对于在 react-router 2.x 中遇到此问题的任何人:
您可以使用 browserHistory 来支持相对路由,而不是使用 Link 组件。
// assuming http://site/myanimals
// configure router for hosting in subdirectory
const history = useRouterHistory(createHistory)({
basename: '/myanimals'
});
// then use it ...
import {browserHistory} from 'react-router';
browserHistory.push('about');
// or, for a configured route with 'animal/:id' you can use
// <Route path={'animal:id'} .../>
browserHistory.push('animal/3');
我希望这会有所帮助!
【讨论】: