【发布时间】:2017-08-13 07:44:07
【问题描述】:
这是我的路由配置代码:
<Switch>
<Route exact path='/(home)?' component={TodoListHomePage} />
<Route exact path='/profile/:userId' component={TodoListProfilePage} />
<Route path='/login' component={SignUpAndLogin} />
</Switch>
一切正常,但带有参数的路径很奇怪,第一次点击它工作正常,路径例如
在第 2 次单击时,它会连接 Profile,如下所示:
http://localhost:4000/Profile/Profile/597c1f43a87ca40d38f79a68
然后在例如
http://localhost:4000//Profile/Profile/Profile/Profile/597c1f43a87ca40d38f79a68
这是我点击个人资料链接时调用的函数:
handleProfileClick = (e, {name}) => {
this.setState({ activeItem: name });
this.props.history.push(name.concat('/'.concat(this.props.viewer._id.toString())));
}
【问题讨论】:
-
您正在使用相对路径。只需在连接前添加
/profile。
标签: javascript react-router react-router-dom