【问题标题】:Relative Linking with React-Router与 React-Router 的相对链接
【发布时间】:2016-09-22 13:28:15
【问题描述】:

我们该怎么做?特别是当路径的一部分是参数(:someParam)时。我在文档中找不到任何内容。

【问题讨论】:

标签: reactjs react-router


【解决方案1】:

现在建议在这种情况下使用 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');

我希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-29
    • 2017-06-11
    • 2016-09-10
    • 2017-08-12
    • 2017-05-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多