简体   繁体   English

路由不更新react-router

[英]Route doesn't update react-router

Route doesn't change when i clicking on <Link /> 当我点击<Link />时,路线不会改变

Browser hash changed but view - don't 浏览器哈希值已更改,但视图-不

Routes 路线

<Router {...this.props}>
                <Route  path="/" component={App}>
                    <Route path="/profile" onEnter={this.requireAuth}>
                        <IndexRoute component={Profile} />
                        <Route path="/profile/update" component={ProfileUpdate} onEnter={this.requireAuth} />
                        <Route path="/profile/:id" component={User} ></Route>
                    </Route>
                </Route>
            </Router>

So i'm trying to navigate there /profile/:id 所以我想在那里导航/profile/:id

Here is my link button 这是我的链接按钮

<Link to={`/profile/${item.id}`}>
       Example link
</Link>

Also when i manually write id in my browser i'm getting error in my console but view shown 另外,当我在浏览器中手动写入id ,控制台中出现错误,但显示的视图

http://myapp.localhost/profile/undefined 404 (Not Found)

How to resolve problems? 如何解决问题? Thanks 谢谢

Check if your item.id is not undefined, if so Link is propably trying to change route from /profile to /profile . 检查您的item.id是否未定义,如果是,那么Link可能试图将路由从/ profile更改为/ profile Since urls are the same react-router won't do anything. 由于网址是相同的,react-router不会做任何事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM