-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make switchLocalePath work from Nuxt plugin or middleware
switchLocalePath didn't work from a Nuxt plugin or middleware (from context.app) as it accessed properties on `this` that were not accessible from there. Fixed by creating a proxy interface that is consistent for both Vue instances and Nuxt context so that switchLocalePath can access same properties from it and get expected results. Also: - Updated `differentDomains` tests to not use snapshot testing. Those actually were wrongly tested due to bug in test utils but failure wasn't caught in snapshot (it was supposed to have SEO disabled). Resolves #480
- Loading branch information
Showing
7 changed files
with
191 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function ({ app, route }) { | ||
const localeCodes = app.i18n.locales.map(locale => locale.code) | ||
|
||
// Tests localePath, switchLocalePath and getRouteBaseName from app context. | ||
app.allLocalePaths = localeCodes.map(locale => app.switchLocalePath(locale)) | ||
app.routeBaseName = app.getRouteBaseName() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<template> | ||
<div> | ||
<div id="paths">{{ allLocalePaths }}</div> | ||
<div id="name">{{ routeBaseName }}</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
middleware: ['i18n-middleware'], | ||
nuxtI18n: { | ||
paths: { | ||
en: '/middleware', | ||
fr: '/middleware-fr' | ||
} | ||
}, | ||
data() { | ||
return { | ||
allLocalePaths: [], | ||
routeBaseName: '', | ||
} | ||
}, | ||
asyncData({ app }) { | ||
return { | ||
allLocalePaths: app.allLocalePaths.join(','), | ||
routeBaseName: app.routeBaseName | ||
} | ||
} | ||
} | ||
</script> |
Oops, something went wrong.