gpt4 book ai didi

reactjs - 如何使用 react 路由器?

转载 作者:行者123 更新时间:2023-12-03 13:58:44 25 4
gpt4 key购买 nike

我正在使用reactjs和react router。我已将路由器创建为:

ReactDOM.render(
<Router history={browserHistory}>
<Route exact path="/" component={App} />
<Route path="/:id" component={User} />
</Router>,
document.getElementById('root')
);

在应用程序组件中,我有一个指向 "/:id" 路径的链接:

<Link to={'/'+id} >

当我在“/” route 时,我的 View 工作正常,但现在当我单击链接时,路径发生变化,我的 View 瞬间发生变化,然后在应用程序组件中给出错误(它是另一条路线)。

我使用"react-router": "^2.8.1"。

PS: the error is in the setinterval function in the component {App}.

感谢您提前提供的帮助

最佳答案

尝试在顶部使用它:

import { Link } from 'react-router-dom'

引用这个:https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/docs/api/Link.md

关于reactjs - 如何使用 <Link> react 路由器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46421496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com