Home > database >  Persian routing in nextjs
Persian routing in nextjs

Time:01-23

I want to have Persian routing like:

"http://mywebsite.com/سلام"

"http://mywebsite.com/شروع/پایان"

"http://mywebsite.com/[slug]/پایان"

What should I do?

Nextjs routing is based on file path, so renaming file names to Persian is not the right thing.

CodePudding user response:

You can do this with rewrites in the next.config.js file.

https://nextjs.org/docs/api-reference/next.config.js/rewrites

Here is an example:

module.exports = {
async rewrites() {
    return {
        beforefiles: [{
                source: '/:slug/پایان',
                destination: '/:slug/somewhere',
            },
            {
                source: '/:slug/پایان',
                destination: '/:slug/somewhere'
            }
        ],
    }
  }
}

You need to have two rewrites for each route, one normal and one url encoded.

  • Related