Eobard Thawn
Eobard Thawn

Reputation: 65

How can i custom nextjs URL in production mode

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

Upvotes: 0

Views: 872

Answers (1)

Edrian
Edrian

Reputation: 608

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

Upvotes: 2

Related Questions