简体   繁体   English

Next.js 404 刷新

[英]Next.js 404 on refresh

I have Next.js page like page.js so it can be reach through http://localhost:3000/page .我有像page.js这样的 Next.js 页面,因此可以通过http://localhost:3000/page访问它。 But for some reason I would like to get this page through an another url http://localhost:3000/my-page但出于某种原因,我想通过另一个 url http://localhost:3000/my-page获取此页面

So I used Link component like this way所以我像这样使用 Link 组件

<link href="/page" as="my-page">
    <a>
        My link to page
    </a>
</link>

Problem is that if I refresh browser, I get a 404 error page if I do not use as property it works.问题是,如果我刷新浏览器,如果我不使用它工作as属性,我会得到一个 404 错误页面。

How can I prevent this behavior?我怎样才能防止这种行为?

This is because you're using a SPA, in this cases the router is different because the routes are loaded with the principal component这是因为您使用的是 SPA,在这种情况下路由器是不同的,因为路由加载了主要组件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM