1

I have user's profile and the route is:

<Route path="/profile/:username" component={UserProfile} />

The link to go to user profile is on Header, like this:

<Link to={`/profile/${props.username}`}>
   <strong>{props.username}</strong> 
</Link>

So, profile's url is localhost:3000/profile/username

There's another component UserPosts. There's a link on user profile, when clicked, shows user feed. Now I want the url like locahost:3000/profile/username/posts

How should my react Route component look like? The thing is I'm getting user's posts by id.

Backend route is: /posts/:id

And, how my Link should look like on the UserProfile component?

<Link to="">
   My Posts
</Link>

And, how should I set my routes. Here is my App.js currently.

      <div>
          <Router>
            <Switch>
              <Route exact path="/" component={Home} />
              <Route path="/register" component={SignUp} />
              <Route path="/login" component={Login} />
              <PrivateRoute
                path="/post/create"
                component={NewPost}
              />
              <Route path="/profile/:username" component={UserProfile} />
              <Route component={NotFound} />
            </Switch>
          </Router>
        )}
      </div>
    ```
7
  • Have you tried <Link to="posts">? Commented Mar 21, 2020 at 12:46
  • no, I'm asking what should i put in there? <Link to="posts"> doesn't make sense. Commented Mar 21, 2020 at 12:48
  • Did you try it? It's a relative link. Commented Mar 21, 2020 at 12:53
  • i want to do it so that the url will be in the UserPosts component -> /profile/username/posts Commented Mar 21, 2020 at 13:47
  • stackoverflow.com/questions/53711964/… stackoverflow.com/questions/36312453/… Commented Mar 21, 2020 at 13:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.