简体   繁体   English

使用 NextJS 自定义路由名称

[英]Custom route name with NextJS

I started work on NextJS a few days ago, and I'm literally blocked now on something that, I think, is very stupid but I cannot find the solution on Internet...几天前我开始在 NextJS 上工作,现在我真的被阻止了,我认为这是非常愚蠢的,但我在互联网上找不到解决方案......

For the moment my website has 4 pages ( Dashboard, Connexion, Register and Notes ) which are in ' pages ' folder at the same level than 'components' folder which has Content, Footer, Header, Layout and Navigation.js .目前,我的网站有 4 个页面(仪表板、连接、注册和注释),它们位于“页面”文件夹中,与“组件”文件夹处于同一级别,该文件夹具有内容、页脚、Header、布局和 Navigation.js Well, I have also a 'public' folder which contain a 'build' folder which has admin.js, app.css, app.js, two files.json and two others.js.好吧,我还有一个“公共”文件夹,其中包含一个“构建”文件夹,其中包含 admin.js、app.css、app.js、两个文件。json 和两个 other.js。

Now, if I want to go on register page I have to type in the URL /register but I would have to type /inscription to go in.现在,如果我想在注册页面上输入 go,我必须输入 URL /register但我必须输入/inscription到 go。

Hoping you understand everything and if you have any question, ask me: Thank you !希望你明白一切,如果你有任何问题,问我:谢谢! :) :)

At the top of your folder inside pages folder you should create, dashboard.js, connection.js, register.js, notes.js.您应该在 pages 文件夹内的文件夹顶部创建dashboard.js、connection.js、register.js、notes.js。

Then if you run npm run dev you should be able to get in the url: http://localhost:3000/register然后如果你运行npm run dev你应该可以进入 url: http://localhost:3000/register

If you want to show your register page as SomeOtherPage you can use code below.如果您想将您的注册页面显示为 SomeOtherPage,您可以使用下面的代码。

// pageWithLink.js
import Link from "next/link";
export default () => (
  <div>
    <Link href="/register" as="/SomeOtherPage">
      <a>Some Other Page</a>
    </Link>
  </div>
);

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

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