我正在使用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(不需要知道国家/地区 ISO 是否正确,只需知道它符合语法即可)。
最佳答案
解决方案似乎是;
<Route path={['/:a([a-zA-Z]{2}\/[a-zA-Z]{2})/about', '/about']} component={AboutPage} />
需要两种语言环境,或者不需要。
关于javascript - 如何使用 React-Router 支持路由中的可选本地化字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55163595/