Skip to content

Commit 8624896

Browse files
authored
Merge pull request #10 from AnderRV/fix/unprefixed-strategy-locale
Fix unprefixed strategy when URL starts with another locale
2 parents 5ad4481 + ca5e016 commit 8624896

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
"README.md"
5353
],
5454
"jest": {
55-
"testRegex": "(/tests/.*|(\\.|/)(test|spec))\\.jsx?$"
55+
"testRegex": "(/tests/.*|(\\.|/)(test|spec))\\.jsx?$",
56+
"testURL": "http://localhost"
5657
},
5758
"babel": {
5859
"presets": [

src/languageStrategy/defaultUnprefixed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import renderTranslatedRoutes from './../renderTranslatedRoutes.js';
1414
import pathFromRouteForPathsAndLocale from './pathFromRouteForPathsAndLocale.js';
1515

1616
const localeFromLocation = (locales, defaultLocale) => location => {
17-
const match = /^\/([a-z]{2}).*/g.exec(location.pathname);
17+
const match = /^\/([a-z]{2})(\/|$).*/g.exec(location.pathname);
1818
if (match && locales.indexOf(match[1]) > -1) {
1919
return match[1];
2020
}

tests/languageStrategy/defaultUnprefixed.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ test('It detects locale based in location', () => {
2828
expect(
2929
languageStrategy.localeFromLocation({pathname: '/eu/some-route'}),
3030
).toBe('eu');
31+
expect(
32+
languageStrategy.localeFromLocation({pathname: '/estrategy-url'}),
33+
).toBe('en');
3134
});
3235

3336
test('Generates valid react-router-config tree', () => {

0 commit comments

Comments
 (0)