hozana / next-translate-routes

Flexible and translated routes for Next.js without custom server
MIT License
115 stars 30 forks source link

Redirection issue using getServerSideProps #82

Closed MaxTec closed 12 months ago

MaxTec commented 1 year ago

Describe the bug

I've encountered a redirection issue when utilizing getServerSideProps on my project. The expected behavior is that visiting "/en/contact" would redirect to "/contact" since I have set the default language to English. However, the redirection fails to occur when getServerSideProps is utilized. When I remove getServerSideProps, the redirection works as expected.

To Reproduce

Steps to reproduce the behavior:

  1. Set up next-translate-routes with English as the default language.
  2. Create a /contact page and implement getServerSideProps.
  3. Visit "/en/contact" in the browser.
  4. Observe that the redirection to "/contact" does not occur.

System information

cvolant commented 1 year ago

Yes, you are right. Unfortunately, this cannot be fixed using next-translate-route approach: trying to use a redirect would lead to a looping redirection. The only way to do this seems to be using the middleware, as stated here. I will update next-translate-routes docs to mention it.

cvolant commented 12 months ago

Added to the docs here.