[英]NextJS index and endpoint share the same page
I have few pages in my Next.js application, and i would like that going into http://localhost:3000/someEndpoint would be exactly the same component loaded as http://localhost:3000/我的 Next.js 应用程序中有几页,我希望进入 http://localhost:3000/someEndpoint 的组件与 http://localhost:3000/ 加载的组件完全相同
I already have created index.js file, but i dont know how can make some virtual URL?我已经创建了 index.js 文件,但我不知道如何创建一些虚拟 URL?
Redirections are not the options, cause i would like to remain "/" endpoint also possible.重定向不是选项,因为我想保持“/”端点也是可能的。
Is there any way to accomplish this?有什么办法可以做到这一点吗?
You can use nextjs rewrites , which works as a URL masking for any URL.您可以使用nextjs 重写,这可以作为一个URL屏蔽任何URL。
module.exports = {
async rewrites() {
return [
{
source: '/someEndpoint',
destination: '/',
},
]
},
}
So now every request on http://localhost:3000/someEndpoint will lands the user to http://localhost:3000/ without redirection.所以现在 http://localhost:3000/someEndpoint 上的每个请求都会让用户访问 http://localhost:3000/ 而无需重定向。 It will work as a proxy url
它将用作代理网址
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.