0

I have a component called Profile and it has two children components Timeline and Friends.

I can route to the timeline component inside profile from any other component like this:

<Link to={{ pathname: '/dashboard/profile/timeline/'+userId}}></Link> 

But once I am in this url, after that if I want to route to friends section, which is a sibling to timeline I try routing using this in Profile component

<Route path="/dashboard/profile/:screenId/:userId" component={this.Routing}/>

where Routing function is

Routing =({ match })=>{
    switch(match.params.screenId){
        case "timeline": return <Timeline/>;
        case "friends": return <Friends/>
        default : return <NoMatch/>;
    }
}

But the problem is it is not working, the Routing function is not being triggered when I click on the navlink

<NavLink to={'/dashboard/profile/'  + (tab.url) + '/' + userId} activeClassName="selectedTab">
   <div>{tab.name}</div>
</NavLink>

This navlink is in the Profile component. Any help would be appreciated.

Saurav Dutta
  • 83
  • 2
  • 10

1 Answers1

0

You need to pass on the Router props to the component in order for Routing to take place

Routing =({ match, ...rest })=>{
    switch(match.params.screenId){
        case "timeline": return <Timeline match={match} {...rest}/>;
        case "friends": return <Friends match={match} {...rest}/>
        default : return <NoMatch match={match} {...rest}/>;
    }
}
Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400