我有两个标签:个人资料和朋友以及导航链接如下
<Navlink to={'/dashboard/profile/' + (tab.url) + '/' + userId}>{tab.name}</Navlink>
其中 tab = [{ "name": "Profile", "url": 'timeline' }, { "name": "Friends", "url": 'friends' }]
在我的 render() 中,我将路由定义为
<Route path="/dashboard/profile/:screenId/:userId" component={this.Routing}/>
其中screenId是 Timeline/Friends 取决于单击哪个选项卡
并且路由功能是
Routing =({ match })=>{
userId = match.params.userId;
switch(match.params.screenId){
case "timeline": return <Timeline/>;
case "friends": return <Friends/>
default : return <NoMatch/>;
}
}
So the problem is whenever any tab is being selected, the url changes but the Routing function is not triggered so as a result the route is not working. 基本上/dashboard/profile/之后的任何东西都不起作用。
我也在我的渲染()中尝试了这个:
<Switch>
<Route path="/dashboard/profile/timeline/userId" component={Timeline}/>
<Route path="/dashboard/profile/friends/userId" component={ContactUs}/>
</Switch>
但是它也不起作用,问题仍然存在。任何帮助,将不胜感激。