fix(nuxt): use `router.resolve` to resolve initial url (#4770)

This commit is contained in:
Daniel Roe 2022-05-03 10:31:58 +01:00 committed by GitHub
parent 686bd84d58
commit f74a523f13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View File

@ -185,7 +185,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
nuxtApp.hooks.hookOnce('app:created', async () => {
try {
await router.replace({
path: initialURL,
...router.resolve(initialURL),
force: true
})
} catch (error) {

View File

@ -59,6 +59,18 @@ describe('pages', () => {
await expectNoClientErrors('/not-found')
})
it('preserves query', async () => {
const html = await $fetch('/?test=true')
// Snapshot
// expect(html).toMatchInlineSnapshot()
// should render text
expect(html).toContain('Path: /?test=true')
await expectNoClientErrors('/?test=true')
})
it('/nested/[foo]/[bar].vue', async () => {
const html = await $fetch('/nested/one/two')

View File

@ -7,6 +7,7 @@
<div>RuntimeConfig | testConfig: {{ config.testConfig }}</div>
<div>Composable | foo: {{ foo }}</div>
<div>Composable | bar: {{ bar }}</div>
<div>Path: {{ $route.fullPath }}</div>
<NuxtLink to="/">
Link
</NuxtLink>