标签: javascript dom
我创建了一个组件,可以在其中通过window.location.pathname获取路由名称,它可以正常工作并为我提供路由名称,但是我想从路由名称中删除正斜杠/。我是ReactJS的初学者,请帮助我如何解决此问题?
window.location.pathname
/
const pathName=window.location.pathname;
答案 0 :(得分:1)
您只能使用substr在/之后输入字符串
const pathName= window.location.pathname.substr(1,) console.log(pathName)