简体   繁体   English

Next.js中如何切换内容

[英]How to switch content in Next.js

So I have a main dashboard on my app, in which I have a sidebar navigation and content container.所以我的应用程序上有一个主仪表板,其中有一个侧边栏导航和内容容器。 But since I`m new to next.js and unfamiliar with its routing system, I don't know how to implement content changing when a user uses sidebar navigation.但是由于我是 next.js 的新手并且不熟悉它的路由系统,所以我不知道如何在用户使用侧边栏导航时实现内容更改。 Should I make a separate page for each navigation route?我应该为每条导航路线制作一个单独的页面吗?

Yes, for each route your have to create a file in pages directory.是的,对于每条路线,您必须在pages目录中创建一个文件。

  • for route / you create the file pages/index.js对于路由/您创建文件pages/index.js
  • for route my-page you create the file pages/my-page.js为路由my-page创建文件pages/my-page.js
  • for route path/my-page you create the folder pages/path and the file pages/folder/my-file.js对于路由path/my-page ,您创建文件夹pages/path和文件pages/folder/my-file.js

For more explanation you can read the documentation of Next.js on routing .有关更多说明,您可以阅读有关路由的 Next.js 的文档 And you can also follow the official tutorial to get basic knowledge of Next.js.并且您也可以按照官方教程获取Next.js的基础知识。

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

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