如果我在NextJS中有一个带有index.js和[id].js文件的index.js文件夹,那么这个浅路由将在index.js文件中工作:
router.push("/posts", "/posts/" + id, {shallow: true})但是,如果我有一个/dynamic-posts文件夹,它不包含index.js,而是包含[category].js文件和id.js,而是包含/post/[id].js,那么这个浅层路由就无法工作:
router.push("/dynamic-post/" + something, "/dynamic-posts/post/" + id, {shallow: true})有人知道怎么修吗?我需要一个搜索引擎优化的动态页面,以排名为一个类似Zillow的webportal城市。例如:https://www.zillow.com/san-francisco-ca/rent-houses/
我在Stackblitz上做了一个演示:https://stackblitz.com/edit/nextjs-ezyusx?file=pages/index.js
发布于 2022-09-06 13:48:42
我找到了一个解决方案,我可以只使用window.history.pushState(),而不是使用Nextjs路由器。
然后,我可以在不引起任何重定向或刷新的情况下更改URL。
https://stackoverflow.com/questions/73619089
复制相似问题