Navlink 仅将其“to"属性值绑定到现有 URL |Material-ui新版本(v1)上的MenuItem [英] Navlink only ties its 'to' attribute value to existing URL | MenuItem on material-ui new version (v1)
问题描述
当我想使用 导航时,如下
When I want to navigate using the <MenuItem>
as follows
<MenuItem onTouchTap={() => {this.handleClose()}}>
<NavLink to="/api/logout">Sign Out</NavLink>
</MenuItem>
这只是将提到的 'to' 属性值 /api/logout
放在链接到现有路由的 URL 中,而不去该路径并最终在浏览器上将链接设为
that is just putting the mentioned 'to' attribute value /api/logout
in the URL linked to the existing route without going to that path and ending up having the link on the browser as http://localhost:3000/api/logout, without going there on the logout route at the nodejs backend server! that is a problem.
请注意,我使用代理将 3000 指向 5000,如下所示
Note that I use proxy to directs from 3000 to 5000 as follows
"proxy": {
"/api/*": {
"target": "http://localhost:5000"
}
},
一般来说,我猜是因为和
的区别.
Generally speaking, I guess that is because the difference between <Link>
and <NavLink>
.
如果你想了解更多关于这个问题是从哪里出现的,你可以看看我之前的帖子 如何使用 MenuItem 进行导航?material-ui V1 但这不是必需的.
If you would like to know more about from where this problem has come out, you can take a look at my previous post how navigate using the MenuItem? material-ui V1 but that is not necessary.
推荐答案
当我将代码更新为:
<MenuItem onClick={this.handleClose} ><a href="/api/logout">Sign Out</a></MenuItem>
这篇关于Navlink 仅将其“to"属性值绑定到现有 URL |Material-ui新版本(v1)上的MenuItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!