Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
71
rated 0 times [  76] [ 5]  / answers: 1 / hits: 27903  / 7 Years ago, tue, march 7, 2017, 12:00:00

In short: I want to show the slug instead of the Id in the URL, whats the best way to do that?



In my app.js component I am using React-router this way so far:



 <Router history={browserHistory}>
<Route path=/ component={Main}>
<IndexRoute component={Home}></IndexRoute>
<Route path=/profile/:slug component={Split}></Route>
</Route>

</Router>


Then in my profile component I am using Link to go to that specific profile via the slug:



<Link to={'/profile/' + username.slug}>{username}</Link>


I was thinking of keying them together in my profile reducer or something?



Any tips would be very helpful!


More From » reactjs

 Answers
17

I would just do it with the way you have set up your route and then as you're using redux (because you said you were before edits) I would use mapStateToProps to filter or however it is you are passing the details as props.



for example:





const mapStateToProps = (state, ownProps) => {
user: state.users.items.filter(user => user.slug === ownProps.params.slug),
}

[#58636] Monday, March 6, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devinjadong

Total Points: 711
Total Questions: 117
Total Answers: 100

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
;