Shallow routing for dynamic routes
See original GitHub issueHi. Is there a way with next.js v9 to navigate from /post/123
to /post/124
shallowly?
Here’s my page structure:
pages
post
[id]
Tried
const href = `/post/124`
const as = href
Router.push(href, as, {shallow: true})
when I’m on /post/123
page with no luck (the page refreshes).
What I need to achieve - I have a sidebar with posts list on the left of the page and selected post on the right. So when clicking a post title in sidebar I show it on the right and I also need to update the url, without refreshing the page.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:21 (11 by maintainers)
Top Results From Across the Web
Shallow Routing - Next.js
Shallow routing allows you to change the URL without running data fetching methods again, that includes getServerSideProps , getStaticProps , and ...
Read more >Next.js - Shallow routing with dynamic routes - Stack Overflow
Shallow Routing gives you the ability to update pathname or query params without losing state i.e., only the state of route is changed.....
Read more >How to Change URLs with Shallow Routing in Next.js - Netlify
Shallow routing is when you change your website's URL without re-running data fetching methods again. In the case of Next.js, it means you...
Read more >Routing in Next.js - Topcoder
Routing with pages. Nested routes. Dynamic routes. Catch-all routes. Navigate from UI. To get started, create a Next.js application using ...
Read more >Understanding Next.js routeChangeStart and router events
Shallow routing allows you to make changes to the path of a page without running data fetching methods again. It helps retain the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh my god, I was understanding
[postId]
as a macro to be replaced by me when coding but, in fact, It is[postId]
literally what have to be wroten. Now that I’ve understood that it works like a charm.Sorry and thank you very much @Timer @timneutkens for your patience. 😃
For future stupids, like me, what have to be replaced during your program execution is the
as
part but not thehref
(that is a literal string declaring your filesystem path):href
is the path inside the pages directoryas
is the url in the browserSee docs here: https://nextjs.org/docs#dynamic-routes