How can i custom nextjs URL in production mode

假装没事ソ 提交于 2019-12-25 01:38:09

问题


When i start my next project with npm run start for cart page i got http://localhost:3000/cart but what i want is for the cart.js is to visit via http://localhost:3000/myprojectname/cart I try to use set in next.config.js with exportpathmap it works well in npm run dev but when i start program with npm run start it doesn't work as i expected how can i get URL path like this http://localhost:3000/myprojectname/cart instead of http://localhost:3000/cart for the cart page


回答1:


What you wanna do is in you project's pages folder, you create a folder named myprojectname. Then inside the folder, move your cart.js.

What this does is it adds a /myprojectname/ route to your URLs and to access the cart, you would have to access it like so: /myprojectname/cart

This is how NextJS does routing, based on how you structure your directories.

For more information, you can refer to this link: https://nextjs.org/learn/basics/navigate-between-pages



来源:https://stackoverflow.com/questions/59246368/how-can-i-custom-nextjs-url-in-production-mode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!