diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1d1f6e001..a77c5d05c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,16 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
+
+# [1.1.0](https://github.com/paulgv/nuxt-i18n/compare/v1.0.2...v1.1.0) (2018-01-22)
+
+
+### Features
+
+* Add ignorePaths option ([1a0fc57](https://github.com/paulgv/nuxt-i18n/commit/1a0fc57))
+
+
+
## [1.0.2](https://github.com/paulgv/nuxt-i18n/compare/v1.0.1...v1.0.2) (2017-12-07)
diff --git a/README.md b/README.md
index 4f2fb9127..0b1ac0755 100755
--- a/README.md
+++ b/README.md
@@ -181,6 +181,7 @@ In the app, you'll need to preserve the language when generating URLs. To do thi
| `defaultLocale` | String | The app's default locale, URLs for this language won't be prefixed with the locale code |
| `vueI18n` | Object | Configuration options for vue-i18n, refer to [the doc](http://kazupon.github.io/vue-i18n/en/api.html#constructor-options) for supported options |
| `routes` | Object | Custom routing configuration, if routes are omitted, Nuxt's default routes are used |
+| `ignorePaths` | Array | A list of paths that should not be localized |
## Configuration example
@@ -232,7 +233,10 @@ module.exports = {
'category-slug': {
fr: '/categorie/:slug'
}
- }
+ },
+ ignorePaths: [
+ '/fr/notlocalized'
+ ]
}]
]
}
diff --git a/lib/module.js b/lib/module.js
index 8407c74a5..94532f1b9 100644
--- a/lib/module.js
+++ b/lib/module.js
@@ -12,7 +12,8 @@ module.exports = function (moduleOptions) {
baseRoutes: routes,
locales: options.locales,
defaultLocale: options.defaultLocale,
- routesOptions: options.routes
+ routesOptions: options.routes,
+ ignorePaths: options.ignorePaths
})
routes.splice(0, routes.length)
routes.unshift(...newRoutes)
diff --git a/lib/routes.js b/lib/routes.js
index ad156c9b3..0698b89c4 100644
--- a/lib/routes.js
+++ b/lib/routes.js
@@ -8,13 +8,30 @@ const { has } = require('lodash')
* defaults to app's configured LOCALES
* @return {Array} Localized routes to be used in Nuxt config
*/
-const generateRoutes = ({ baseRoutes, locales, defaultLocale, routesOptions, isChild = false }) => {
+const generateRoutes = ({
+ baseRoutes,
+ locales,
+ defaultLocale,
+ routesOptions,
+ ignorePaths = [],
+ isChild = false }) => {
// Abort routes generation if no routes or locales specified
if (!baseRoutes || !locales) {
return []
}
const newRoutes = []
- baseRoutes.forEach((baseRoute) => {
+ const localizedRoutes = []
+
+ // Extract routes that should not be localized
+ baseRoutes.forEach(route => {
+ if (ignorePaths.indexOf(route.path) !== -1) {
+ newRoutes.push(route)
+ } else {
+ localizedRoutes.push(route)
+ }
+ })
+
+ localizedRoutes.forEach(baseRoute => {
locales.forEach((locale) => {
const { component } = baseRoute
let { path, name, children } = baseRoute
@@ -24,6 +41,7 @@ const generateRoutes = ({ baseRoutes, locales, defaultLocale, routesOptions, isC
locales: [locale],
defaultLocale,
routesOptions,
+ ignorePaths,
isChild: true
})
}
diff --git a/package.json b/package.json
index d2fa195dd..b7874a2a6 100755
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "nuxt-i18n",
- "version": "1.0.2",
+ "version": "1.1.0",
"description": "i18n for Nuxt",
"license": "MIT",
"contributors": [
diff --git a/test/fixture/nuxt.config.js b/test/fixture/nuxt.config.js
index 416537e64..6028f04b4 100644
--- a/test/fixture/nuxt.config.js
+++ b/test/fixture/nuxt.config.js
@@ -38,14 +38,11 @@ module.exports = {
about: {
fr: '/a-propos',
en: '/about-us'
- },
- category: {
- fr: '/categorie'
- },
- 'category-slug': {
- fr: '/categorie/:slug'
}
- }
+ },
+ ignorePaths: [
+ '/fr/notlocalized'
+ ]
}]
]
}
diff --git a/test/fixture/pages/fr/notlocalized.vue b/test/fixture/pages/fr/notlocalized.vue
new file mode 100644
index 000000000..8d52263ee
--- /dev/null
+++ b/test/fixture/pages/fr/notlocalized.vue
@@ -0,0 +1,10 @@
+
+
+ FR only
+
+
+
+
diff --git a/test/module.test.js b/test/module.test.js
index 1706aa582..ab9f5da4e 100644
--- a/test/module.test.js
+++ b/test/module.test.js
@@ -57,6 +57,27 @@ describe('Module', () => {
expect(html).toContain('Accueil')
})
+ test('/fr/notlocalized contains FR text', async () => {
+ let html = await get('/fr/notlocalized')
+ expect(html).toContain('FR only')
+ })
+
+ test('/notlocalized & /fr/fr/notlocalized return 404', async () => {
+ let response
+ try {
+ response = await get('/notlocalized')
+ } catch (error) {
+ response = error
+ }
+ expect(response.statusCode).toBe(404)
+ try {
+ response = await get('/fr/fr/notlocalized')
+ } catch (error) {
+ response = error
+ }
+ expect(response.statusCode).toBe(404)
+ })
+
test('/posts contains EN text, link to /fr/posts/ & link to /posts/my-slug', async () => {
let html = await get('/posts')
expect(html).toContain('Posts')