2.0.0 • Published 4 years ago

nextjs-redirect-locale v2.0.0

Weekly downloads
7
License
MIT
Repository
github
Last release
4 years ago

nextjs-redirect-locale

Install

npm install nextjs-redirect-locale

Usage

Let's say you have a next.js project (like this one) that creates one route per locale automatically, i.e. a page like page/home.js will be available in different languages with the following routes:

  • /en/home
  • /es/home
  • /gl/home
  • /fr/home
  • /fr_CA/home

If you want to redirect to the proper locale once the user visits /, then you can create a pages/index.js with the following code:

import redirectLocale from 'nextjs-redirect-locale'
export default redirectLocale(['en', 'es', 'gl', 'fr', 'fr_CA'])

Result: / redirects to /es/ (if user locale is es)

Keep in mind the first locale is gonna be the default (i.e. the one that gets selected if the user locale is not on the list).

You can checkout this example live in pablo.pink

Static export

This package is compatible with static exports via next export since version 2.0.0

Related

License

MIT

Author

me
Pablo Varela