如何使用React-Router

时间:2019-03-14 13:17:50

标签: javascript reactjs react-router react-router-v4

我正在使用react-router,我需要允许链接的国际化;所以这是一个大纲;

domain.com/langISO/countryISO2/page

这些都是有效的路线;

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)

所以就像

langISo或CountryISO将始终是一对两个字符串,并且将是有效的国家/地区ISO(它不需要知道countryISO是否正确,只要知道它符合语法即可。)

1 个答案:

答案 0 :(得分:1)

解决方案似乎是

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

需要两个语言环境,或者都不需要。