Next.js Discord

Discord Forum

Navigation from /category/gaming to /userName/list123 without refreshing the page

Unanswered
Mallow bee posted this in #help-forum
Open in Discord
Mallow beeOP
Hi, I have a dynamic category route as followed:
example.com/category/gaming
example.com/category/fashion

Within each category, there are posts created by different users.
When clicking each post, a modal is opened with its content and now I want it to change to the following URL format:

example.com/userName/somePost
example.com/anotherUser/anotherPost123

How can I do that without a page reload?

I'm using next/link but when the url changes it automatically redirects the user.

5 Replies

I think you should take a look at useTransition hook of react
I'm not sure if i got your problem but maybe it can be helpful
Mallow beeOP
I looked into that, but it doesn't solve the problem

I'm sharing this simpler example of my Header component -
     <Link href="/" as="/login">
          <Button variant="default" size="lg">
            Sign in
          </Button>
        </Link>


This link opens a login modal.
When I'm in / it works - the modal opens and no redirection happen.
But when I'm in /category/example i'm being redirected to /login
in that link component u have an href so it s normal actually
why you use link element to open a modal?