Client-side (SPA) routing when moving from SSR
Unanswered
Blanc de Hotot posted this in #help-forum
Blanc de HototOP
Hi,
I've found need to move into SPA only and remove all SSR features.
Noticed that the nextjs v14 router
I got at hands a project that was badly architected. One of the issue's being on routing.
As I'm deprecating SSR, I'd like to know what'd be the best practice on handling client-side only routing.
Some of the use-cases to consider:
- HTTP Server response is
- On any route
- On refresh of any pathname, e.g.
This should give you a basic idea of the process I'd liek to achieve, so I need to understand what are the best practices when dealing with nextjs v14 routing for client-side only. Specially when deprecating the SSR.
Thank you!
I've found need to move into SPA only and remove all SSR features.
Noticed that the nextjs v14 router
next/router
, e.g. router.pathname
differs from window.location.pathname
on runtime.I got at hands a project that was badly architected. One of the issue's being on routing.
As I'm deprecating SSR, I'd like to know what'd be the best practice on handling client-side only routing.
Some of the use-cases to consider:
- HTTP Server response is
/index.html
only, e.g. no static file for each page
or route
- On any route
/
, /app/foobar/something
I want the entry point to resolve it, e.g. as what next/router
seem to do- On refresh of any pathname, e.g.
/app/foobar/one
it should resolve itThis should give you a basic idea of the process I'd liek to achieve, so I need to understand what are the best practices when dealing with nextjs v14 routing for client-side only. Specially when deprecating the SSR.
Thank you!
1 Reply
Briard
import { useRouter } from "next/navigation";
use this for navigation on client side