dhj
dhj

Reputation: 4805

How to support optional localisation strings in routes with React-Router

I am using react-router I need to allow the internationalisation of links; so this is an outline;

domain.com/langISO/countryISO2/page

these would all be valid routes as an example;

domain.com/ -> Home Page
domain.com/en/us -> Home Page
domain.com/fr/fr -> Home Page
domain.com/en/gb/settings -> Settings Page
domain.com/en/gb/account -> Account Page
domain.com/settings -> Settings Page
domain.com/es/us -> Homepage (with spanish and united states localisation)

So its like

The langISo or CountryISO will always be in a pair of two character strings and will be a valid country ISO (it does not need to know if the countryISO is correct or not, just that it meets the syntax).

Upvotes: 0

Views: 38

Answers (1)

dhj
dhj

Reputation: 4805

The solution seems to be;

<Route path={['/:a([a-zA-Z]{2}\/[a-zA-Z]{2})/about', '/about']} component={AboutPage} />

Requires both locales, or none.

Upvotes: 1

Related Questions