Skip to content

Commit

Permalink
feat!: change index fallback behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
serkodev committed Apr 20, 2024
1 parent c42c921 commit b7d9d17
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<ExampleView label="$__PAGES_PATH__">
default fallback path
@left index fallback
</ExampleView>
</template>
5 changes: 5 additions & 0 deletions examples/parallel-sidebar/pages/@main/~index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<ExampleView label="$__PAGES_PATH__">
@main index fallback
</ExampleView>
</template>
19 changes: 12 additions & 7 deletions src/runtime/parallel-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default defineNuxtPlugin(async () => {
async function createParallelRouter(name: string, routes: RouteRecord[], router: Router, parallelPageOptions: Partial<ParallelPageOptions>): Promise<ParallelRouter> {
const options = defu(parallelPageOptions, {
mode: 'sync',
index: '/~index',
fallback: true,
} satisfies ParallelPageOptions)

Expand Down Expand Up @@ -136,19 +137,23 @@ async function createParallelRouter(name: string, routes: RouteRecord[], router:
}

async function init() {
async function tryIndex() {
const pushIndex = options.index && tryPush(options.index)
if (pushIndex) {
await pushIndex
} else {
fallback.index = true
}
}

if (options.mode === 'manual') {
if (options.index)
await parallelRouter.push(options.index)
await tryIndex()
} else {
const initSync = sync()
if (initSync)
await initSync
else {
if (options.index) {
await parallelRouter.push(options.index)
} else {
fallback.index = true
}
await tryIndex()
}
}
}
Expand Down

0 comments on commit b7d9d17

Please sign in to comment.