Skip to content

Commit 00c89f1

Browse files
michaelwnycpaulgv
authored andcommitted
feat: Add encodeURI option to allow skipping encodeURI for custom paths (#199)
Fixes #191
1 parent 09b4448 commit 00c89f1

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

docs/options-reference.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ Here are all the options available when configuring the module and their default
106106
// the pages option, refer to the "Routing" section for usage
107107
pages: {},
108108

109+
// By default, custom paths will be encoded using encodeURI method.
110+
// This does not work with regexp: "/foo/:slug-:id(\\d+)". If you want to use
111+
// regexp in the path, then set this option to false, and make sure you process
112+
// path encoding yourself.
113+
encodeURI: true,
114+
109115
// Called right before app's locale changes
110116
beforeLanguageSwitch: () => null,
111117

docs/routing.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,32 +175,47 @@ You would need to set up your `pages` property as follows:
175175
pages: {
176176
about: {
177177
en: '/about',
178-
fr: '/a-propos',
178+
fr: '/a-propos',
179179
},
180180
'services/index': {
181181
en: '/services',
182-
fr: '/offres',
182+
fr: '/offres',
183183
},
184184
'services/development/index': {
185185
en: '/services/development',
186-
fr: '/offres/developement',
186+
fr: '/offres/developement',
187187
},
188188
'services/development/app/index': {
189189
en: '/services/development/app',
190-
fr: '/offres/developement/app',
190+
fr: '/offres/developement/app',
191191
},
192192
'services/development/website/index': {
193193
en: '/services/development/website',
194-
fr: '/offres/developement/site-web',
194+
fr: '/offres/developement/site-web',
195195
},
196196
'services/coaching/index': {
197197
en: '/services/coaching',
198-
fr: '/offres/formation',
198+
fr: '/offres/formation',
199199
}
200200
}
201201
}]
202202
```
203203
204+
### Regular Expression
205+
206+
By default, all custom paths are encoded to handle non-latin characters in the path. This will convert paths with regular expression like `/foo/:slug-:id(\\d+)` to `/foo/:slug-:id(%5Cd+)`.
207+
208+
If you would like to use regular expression in your custom paths, then you need to set the `encodeURI` option to false. Since no encoding will happen, you will have to make sure to pass in encoded paths yourself.
209+
210+
```js
211+
// nuxt.config.js
212+
213+
['nuxt-i18n', {
214+
encodeURI: false
215+
}]
216+
```
217+
218+
204219
## Ignore routes
205220
206221

src/helpers/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ exports.DEFAULT_OPTIONS = {
5151
},
5252
parsePages: true,
5353
pages: {},
54+
encodeURI: true,
5455
beforeLanguageSwitch: () => null,
5556
onLanguageSwitched: () => null
5657
}

src/helpers/routes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ exports.makeRoutes = (baseRoutes, {
1111
strategy,
1212
parsePages,
1313
pages,
14+
encodeURI,
1415
pagesDir,
1516
differentDomains
1617
}) => {
@@ -77,7 +78,7 @@ exports.makeRoutes = (baseRoutes, {
7778

7879
// Get custom path if any
7980
if (componentOptions.paths && componentOptions.paths[locale]) {
80-
path = encodeURI(componentOptions.paths[locale])
81+
path = encodeURI ? encodeURI(componentOptions.paths[locale]) : componentOptions.paths[locale]
8182
}
8283

8384
// Add route prefix if needed

0 commit comments

Comments
 (0)