How to keep language in URL?


#1

Hi all,

I want to keep language in URL as:

How can I do that with Route group & prefix? (or any solution)

Language code should be passed dynamically as route param

Thank you so much!

p/s: I only want to get language code via route param, not session or cookie :slight_smile:


#2

Hey @donamkhanh! :wave:

What have you tried so far?


#3

Hi @romain.lanz!

I tried:

Route.group(() => {
  Route.resource('users', 'UserController');
}).prefix('en');

Route.group(() => {
  Route.resource('users', 'UserController');
}).prefix('vi');

and use middleware to handler the language code (as the first parameter)

What should we do if we have lot of locales? Must put the route.group into a loop in available locales, right?