Next.js Discord

Discord Forum

Why not router.push?

Unanswered
Masai Lion posted this in #help-forum
Open in Discord
Masai LionOP
Why's the recommendation?

24 Replies

Masai LionOP
I like using router.push on some http responses, and for dynamic navigation.
@Masai Lion I like using router.push on some http responses, and for dynamic navigation.
Because if you just use <Link> you can use it in server components. But if the user clicks it, the user will be redirected. So: same behavior.

I like to use router when I also do something inside my function or I am already on clientside 👍
@B33fb0n3 Because if you just use <Link> you can use it in server components. But if the user clicks it, the user will be redirected. So: same behavior. I like to use router when I also do something inside my function or I am already on clientside 👍
Masai LionOP
I see, i don't use server components at all so it should be fine.

But is it also okay to use router.push other than onClick events and instead in like fetch responses and stuff?
@Masai Lion Why's the recommendation?
because the button above is not a link and hence not SEO friendly (crawlers won't know that it actually links to another page)
it is like, instead of <a href="https://google.com">, you make a button in which the onClick event has window.location.href = "https://google.com"
@joulev it is like, instead of `<a href="https://google.com">`, you make a button in which the onClick event has `window.location.href = "https://google.com"`
Masai LionOP
I know this is unrelated to Next.js but is it alright to do so when not considering SEO and Next.js' server side components?
I don't care about neither and don't wanna refactor my code either unless there is a good reason to do so
@Masai Lion I don't care about neither and don't wanna refactor my code either unless there is a good reason to do so
Of course: it works. And if you don't care about anything, that you are good to go.
Masai LionOP
Not "anything" but just seo and next.js ss components 😄
well alright then.
thank you guys both
with love ❤️ the bad
@Masai Lion I know this is unrelated to Next.js but is it alright to do so when not considering SEO and Next.js' server side components?
UX is bad in the <button> case. you can't hold ctrl and click to open in new tab, you cant right click to get more options on how to open the link, etc
no, as a user for the love of god i beg you do NOT make links buttons
i have suffered enough sites making links as buttons already
i need this for all links and a button won't have it
@joulev no, as a user for the love of god i beg you do NOT make links buttons
Masai LionOP
by link button you mean onClick=router.push?

i see what you mean and now to think about it, i might wrap some components with <a> for that
but for most stuff i think link buttons are fine 😄
i use link buttons for like switcing a tab and stuff
like this;
/room -> /room/info
but for opening rooms, user might wanna have a few rooms open so in there i need to wrap with <a>
long story short i get what you mean
thank you man ❤️