fix: direct does not work in nested route (#15784)

This commit is contained in:
anatawa12 2025-04-09 08:09:08 +09:00 committed by GitHub
parent b40f5b9021
commit 628a0c71a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 11 deletions

View File

@ -266,12 +266,13 @@ export class Nirax<DEF extends RouteDef[]> extends EventEmitter<RouterEvents> {
throw new Error('no route found for: ' + fullPath); throw new Error('no route found for: ' + fullPath);
} }
if ('redirect' in res.route) { for (let current: PathResolvedResult | undefined = res; current; current = current.child) {
if ('redirect' in current.route) {
let redirectPath: string; let redirectPath: string;
if (typeof res.route.redirect === 'function') { if (typeof current.route.redirect === 'function') {
redirectPath = res.route.redirect(res.props); redirectPath = current.route.redirect(current.props);
} else { } else {
redirectPath = res.route.redirect + (res._parsedRoute.queryString ? '?' + res._parsedRoute.queryString : '') + (res._parsedRoute.hash ? '#' + res._parsedRoute.hash : ''); redirectPath = current.route.redirect + (current._parsedRoute.queryString ? '?' + current._parsedRoute.queryString : '') + (current._parsedRoute.hash ? '#' + current._parsedRoute.hash : '');
} }
if (_DEV_) console.log('Redirecting to: ', redirectPath); if (_DEV_) console.log('Redirecting to: ', redirectPath);
if (_redirected && this.redirectCount++ > 10) { if (_redirected && this.redirectCount++ > 10) {
@ -279,6 +280,7 @@ export class Nirax<DEF extends RouteDef[]> extends EventEmitter<RouterEvents> {
} }
return this.navigate(redirectPath, emitChange, true); return this.navigate(redirectPath, emitChange, true);
} }
}
if (res.route.loginRequired && !this.isLoggedIn) { if (res.route.loginRequired && !this.isLoggedIn) {
res.route.component = this.notFoundPageComponent; res.route.component = this.notFoundPageComponent;