【问题标题】:react-router 2.0: # support in configurationreact-router 2.0: # 配置支持
【发布时间】:2016-03-20 22:23:40
【问题描述】:

我从 react-router 0.13.x 升级到 2.0。我注意到 react-router 不再在 url 中呈现主题标签。结果,直接访问时,我的路线不再起作用。

如果我尝试将主题标签直接放在我的配置中,它将无法匹配 url。如何让 react-router 呈现主题标签?它曾经在 0.13.x 版本中默认执行此操作。

render((
    <Router history={browserHistory}>
        <Route path="/" component={App}>
                <Route name="foo" path="/foo" component={Foo}/>
                <Route name="bar" path="/bar" component={Bar}/>
            </Route>
        </Route>
    </Router>
), document.getElementById('app'));

【问题讨论】:

    标签: reactjs react-router


    【解决方案1】:

    path 中删除标签,这看起来很糟糕。您的 browserHistory 需要改为 hashHistory。之前默认有 hashHistory,现在你需要指定它。

    此外,路由不再有 name,如果您想将其嵌套在 /web/dist 路由中,path 不会使用斜线。您应该再次仔细阅读指南。

    【讨论】:

    • 我将删除标签,我只是用来说明我需要的网址。感谢您的信息!
    • 我不是想从问题中删除它,而是从代码中,对不起,你可以把它放回去:)
    • 它还在,当我尝试直接在配置中添加主题标签时,它无法匹配 url。我把它放在那里是为了帮助任何未来的读者。
    猜你喜欢
    • 2023-02-22
    • 2017-10-26
    • 2020-08-13
    • 1970-01-01
    • 1970-01-01
    • 2019-09-20
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    相关资源
    最近更新 更多