-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: common composable option passing (#2737)
* fix: common composable option passing * chore: fix composable JSDoc description * refactor: remove unused code * fix: `resolveRoute` should pass common options to `resolve` * test: add regression tests for `#2736` * chore: add JSDoc description to `CommonComposableOptions` * fix: provide composable options by wrapping * refactor: head composable consistency
- Loading branch information
1 parent
c9bdcd7
commit a94d606
Showing
14 changed files
with
268 additions
and
273 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<script setup lang="ts"> | ||
import { useLocaleHead, useLocalePath, useLocaleRoute, useRouteBaseName, useSwitchLocalePath } from '#i18n' | ||
import { computed, useHead } from '#imports' | ||
const localePath = useLocalePath() | ||
const localeRoute = useLocaleRoute() | ||
const switchLocalePath = useSwitchLocalePath() | ||
const routeBaseName = useRouteBaseName() | ||
const localeHead = useLocaleHead({ addDirAttribute: true, addSeoAttributes: true, identifierAttribute: 'id' }) | ||
const metaTestEntries = computed(() => [ | ||
{ id: 'locale-path', content: localePath('/nested/test-route') }, | ||
{ id: 'locale-route', content: localeRoute('/nested/test-route')?.fullPath ?? '' }, | ||
{ id: 'switch-locale-path', content: switchLocalePath('fr') }, | ||
{ id: 'route-base-name', content: routeBaseName(localeRoute('/nested/test-route', 'fr')) ?? '' } | ||
]) | ||
useHead({ | ||
htmlAttrs: { | ||
...localeHead.value.htmlAttrs | ||
}, | ||
link: () => [...(localeHead.value.link ?? [])], | ||
meta: () => [...(localeHead.value.meta ?? []), ...metaTestEntries.value] | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<NuxtPage /> | ||
</div> | ||
</template> |
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,19 @@ | ||
// https://nuxt.com/docs/guide/directory-structure/nuxt.config | ||
export default defineNuxtConfig({ | ||
modules: ['@nuxtjs/i18n'], | ||
debug: false, | ||
i18n: { | ||
defaultLocale: 'en', | ||
strategy: 'prefix_and_default', | ||
locales: [ | ||
{ | ||
code: 'en', | ||
iso: 'en-US' | ||
}, | ||
{ | ||
code: 'fr', | ||
iso: 'fr-FR' | ||
} | ||
] | ||
} | ||
}) |
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,14 @@ | ||
{ | ||
"name": "nuxt3-test-basic-usage-layers", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "nuxi dev", | ||
"build": "nuxt build", | ||
"start": "node .output/server/index.mjs" | ||
}, | ||
"devDependencies": { | ||
"@nuxtjs/i18n": "latest", | ||
"nuxt": "latest" | ||
} | ||
} |
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,3 @@ | ||
<template> | ||
<h1>Home</h1> | ||
</template> |
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,3 @@ | ||
<template> | ||
<div>Test route</div> | ||
</template> |
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,20 @@ | ||
import { test, expect, describe } from 'vitest' | ||
import { fileURLToPath } from 'node:url' | ||
import { setup, $fetch } from '../utils' | ||
import { getDom } from '../helper' | ||
|
||
describe('#2726 - Composable requires access to the Nuxt instance', async () => { | ||
await setup({ | ||
rootDir: fileURLToPath(new URL(`../fixtures/issues/2726`, import.meta.url)) | ||
}) | ||
|
||
test('Composables correctly initialize common options, no internal server error', async () => { | ||
const html = await $fetch('/') | ||
const dom = getDom(html) | ||
|
||
expect(dom.querySelector('head #locale-path').content).toEqual('/nested/test-route') | ||
expect(dom.querySelector('head #locale-route').content).toEqual('/nested/test-route') | ||
expect(dom.querySelector('head #switch-locale-path').content).toEqual('/fr') | ||
expect(dom.querySelector('head #route-base-name').content).toEqual('nested-test-route') | ||
}) | ||
}) |
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
Oops, something went wrong.