Next.js Discord

Discord Forum

Shallow redirect with App router

Unanswered
XandoR posted this in #help-forum
Open in Discord
Hello there, question might sound stupid but... What's the equivalent of passing { shallow: true } to router.push options when using app router ?

4 Replies

Dwarf Crocodile
You can just use the native history api as stated in the app router documentation. https://nextjs.org/docs/app/building-your-application/routing/linking-and-navigating#using-the-native-history-api
    const params = new URLSearchParams(searchParams.toString())
    params.set('sort', sortOrder)
    window.history.pushState(null, '', `?${params.toString()}`)
@XandoR And so this is the equivalent for shallow navigation ?
Dwarf Crocodile
Yes I think so