diff options
| author | anatawa12 <anatawa12@icloud.com> | 2025-04-09 08:09:08 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-09 08:09:08 +0900 |
| commit | 628a0c71a9fb36f1eb5b542b516be513e11bc30a (patch) | |
| tree | 9a2ab02d0280007e988f65df87f99c1c30f15720 | |
| parent | fix typo (diff) | |
| download | sharkey-628a0c71a9fb36f1eb5b542b516be513e11bc30a.tar.gz sharkey-628a0c71a9fb36f1eb5b542b516be513e11bc30a.tar.bz2 sharkey-628a0c71a9fb36f1eb5b542b516be513e11bc30a.zip | |
fix: direct does not work in nested route (#15784)
| -rw-r--r-- | packages/frontend/src/lib/nirax.ts | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/packages/frontend/src/lib/nirax.ts b/packages/frontend/src/lib/nirax.ts index a97803e879..a166df9eb0 100644 --- a/packages/frontend/src/lib/nirax.ts +++ b/packages/frontend/src/lib/nirax.ts @@ -266,18 +266,20 @@ export class Nirax<DEF extends RouteDef[]> extends EventEmitter<RouterEvents> { throw new Error('no route found for: ' + fullPath); } - if ('redirect' in res.route) { - let redirectPath: string; - if (typeof res.route.redirect === 'function') { - redirectPath = res.route.redirect(res.props); - } else { - redirectPath = res.route.redirect + (res._parsedRoute.queryString ? '?' + res._parsedRoute.queryString : '') + (res._parsedRoute.hash ? '#' + res._parsedRoute.hash : ''); - } - if (_DEV_) console.log('Redirecting to: ', redirectPath); - if (_redirected && this.redirectCount++ > 10) { - throw new Error('redirect loop detected'); + for (let current: PathResolvedResult | undefined = res; current; current = current.child) { + if ('redirect' in current.route) { + let redirectPath: string; + if (typeof current.route.redirect === 'function') { + redirectPath = current.route.redirect(current.props); + } else { + redirectPath = current.route.redirect + (current._parsedRoute.queryString ? '?' + current._parsedRoute.queryString : '') + (current._parsedRoute.hash ? '#' + current._parsedRoute.hash : ''); + } + if (_DEV_) console.log('Redirecting to: ', redirectPath); + if (_redirected && this.redirectCount++ > 10) { + throw new Error('redirect loop detected'); + } + return this.navigate(redirectPath, emitChange, true); } - return this.navigate(redirectPath, emitChange, true); } if (res.route.loginRequired && !this.isLoggedIn) { |