這是我的路線上的配置代碼:反應路由器Dom參數無法正常工作?
<Switch>
<Route exact path='/(home)?' component={TodoListHomePage} />
<Route exact path='/profile/:userId' component={TodoListProfilePage} />
<Route path='/login' component={SignUpAndLogin} />
</Switch>
一切工作正常,但與PARAM路徑怪異,在第一次單擊它例如工作正常,路徑
二號點擊它加到配置文件是這樣的:
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'。 –