Answer the question
In order to leave comments, you need to log in
How can I adequately solve my problem in React Router?
Good evening.
The problem is this:
Let's take Twitter as a basis.
We have a route and a redirect in App.js that serve as the starting point for our routing. Inside the Profile component, everything happens that a regular user has on Twitter. In terms of links the same. And then the question creeps up,
If we click, we will follow the link twitter.com/username Which
means that our version with a redirect will not work.
How can I make it so that when selecting a user and going to his profile, the Profile component continues to be displayed, but with the url of the new user?
Help me please!
<BrowserRouter>
<React.Fragment>
<Nav />
<Switch>
<Route path="/EveryInteract" component={Profile} />
<Redirect exact from="/" to="/EveryInteract" />
</Switch>
</React.Fragment>
</BrowserRouter>
Answer the question
In order to leave comments, you need to log in
More or less like this:
<Switch>
<Route path="/:user_slug" component={Profile} />
{me && <Redirect exact from="/" to={'/' + me.slug} />}
</Switch>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question