0
Challenge · 46Routing & Data
Programmatic Navigation
Coreused in ~80% of apps
A user submits a login form — now what? You can't make them click a link. You need to move the app to a new route from code, the moment your logic decides to.
Core idea. Call the useNavigate() hook to get a navigate function, then trigger a route change from an event handler or effect: navigate('/path') to go somewhere, navigate(-1) to go back, and { replace: true } to overwrite the current history entry instead of adding one.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
app.pulse.dev/login
Login screen
the URL drives which component shows — no full reload
navigation mode for the buttons below
Submit the login form, then redirect to the app:
history stack1 entry
0/login here
Push grows the stack; replace overwrites the top; Back/Forward just move the pointer.
Submit the login form, then navigate around. Watch the URL and the history stack.
↑ play a little first, then dig in