[英]Next js : router.push routes to the target url but reloads it
I have a page structure like我有一个页面结构
pages
[re]
login
[slug.tsx]
From one of the rendered pages, http://localhost:3000/in/login/data1
on button click router.push
is called,从其中一个呈现的页面,
http://localhost:3000/in/login/data1
按钮单击router.push
被调用,
router.push(`in/login/data2`, undefined, { locale });
As expected router.push
routes to the target path with the updated view BUT it reloads the page clearing the redux store.正如预期的那样,
router.push
使用更新的视图路由到目标路径,但它会重新加载页面以清除 redux 存储。 Any pointer to why this is happening?任何关于为什么会发生这种情况的指针?
Note: The issue happens if I directly load http://localhost:3000/in/login/data1
in browser and on click on button to go to http://localhost:3000/in/login/data2
.注意:如果我直接在浏览器中加载
http://localhost:3000/in/login/data1
并单击按钮转到http://localhost:3000/in/login/data2
,就会发生此问题。 But all works fine if go to http://localhost:3000/in/login/data1
from the home page http://localhost:3000/
by clicking on但是如果从主页
http://localhost:3000/
转到http://localhost:3000/in/login/data1
一切正常,点击
<Link href="/in/login/data1">
</Link>
You need something called shallow routing.你需要一种叫做浅层路由的东西。 Shallow routing allows you to change route without page refresh.
浅路由允许您在不刷新页面的情况下更改路由。 All you need to do is pass shallow true in your router.push function like this
您需要做的就是像这样在 router.push 函数中传递 shallow true
router.push(`in/login/data2`, undefined, { shallow: true });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.