what is next.js
Next is a React frontend development web framework that eables functionality such as server-side rendering and static site generation.
server-side rendering
Unlike a traditional React app where the entire application is loaded and rendered on the client, Next.js allows the first page load to be rendered by the server, which is great for SEO & performance.
Next.js 好处
文件结构
顶层文件夹:
- app: App router,在该文件夹下的componets都是server-side components
- pages: Pages router
- public: Static assets to be served
State management in react is primarily handled on the client side
component state is managed and updated within the browser
client-side和server-side适用场景:
router
如何创建:
在app文件夹上创建一个和route对应名称的文件夹,然后在创建的文件夹里创建page.js
嵌套路由:只需要在父路由下进行上述操作即可,也就是创建对应路由名称的文件夹并在里面创建page.js文件
动态路由:只需要对文件夹名字加上“[]"符号即可,在动态路由的page里,{动态路由名字}即可访问对应的值。