繁体   English   中英

路由不更新react-router

[英]Route doesn't update react-router

当我点击<Link />时,路线不会改变

浏览器哈希值已更改,但视图-不

路线

<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>

所以我想在那里导航/profile/:id

这是我的链接按钮

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

另外,当我在浏览器中手动写入id ,控制台中出现错误,但显示的视图

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

如何解决问题? 谢谢

检查您的item.id是否未定义,如果是,那么Link可能试图将路由从/ profile更改为/ profile 由于网址是相同的,react-router不会做任何事情。

暂无
暂无

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

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