2017-08-13 58 views
0

這是我的路線上的配置代碼:反應路由器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/597c1f43a87ca40d38f79a68

二號點擊它加到配置文件是這樣的:

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()))); 
} 
+0

您使用相對路徑。只需在連接之前添加'/ profile'。 –

回答

1

您使用相對路徑。在連接之前只需添加/

handleProfileClick = (e, {name}) => { 
     this.setState({ activeItem: name }); 
     this.props.history.push("/profile/" + this.props.viewer._id.toString()); 
} 
+0

感謝它現在的作品,但是當我重新加載時,無法加載資源:服務器響應狀態爲404(未找到)。可能是什麼原因? –

+0

嗯...我清理了你的'concat'操作..用更新後的代碼試試吧? –

+0

是它的工作,現在,但我有另一個eror當我嘗試重新加載發生,無法加載資源:服務器迴應的404(未找到)狀態,但是當我點擊它,它的偉大工程,只是在配置文件路線(有問題)它重新加載失敗,但在其他路線沒問題。 –