Navlink 仅将其“to"属性值绑定到现有 URL |Material-ui新版本(v1)上的MenuItem [英] Navlink only ties its 'to' attribute value to existing URL | MenuItem on material-ui new version (v1)

查看:30
本文介绍了Navlink 仅将其“to"属性值绑定到现有 URL |Material-ui新版本(v1)上的MenuItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想使用 导航时,如下

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 中,而不去该路径并最终在浏览器上将链接设为 http://localhost:3000/api/logout,无需在 nodejs 后端服务器的注销路由上访问!这是个问题.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆