docs: fix redirect with secondary outlet in router guide example (#29267)
The URL wasn't be parsed into a UrlTree, so redirecting with a secondary route went to a 404 Closes #28805 PR Close #29267
This commit is contained in:
parent
0c59342cd0
commit
2064508876
|
@ -31,6 +31,7 @@ describe('Router', () => {
|
|||
heroDetailTitle: heroDetail.element(by.xpath('*[2]')),
|
||||
|
||||
adminHref: hrefEles.get(2),
|
||||
adminPage: element(by.css('app-root > div > app-admin')),
|
||||
adminPreloadList: element.all(by.css('app-root > div > app-admin > app-admin-dashboard > ul > li')),
|
||||
|
||||
loginHref: hrefEles.get(3),
|
||||
|
@ -138,6 +139,31 @@ describe('Router', () => {
|
|||
expect(page.secondaryOutlet.count()).toBe(1, 'secondary outlet');
|
||||
});
|
||||
|
||||
it('should redirect with secondary route', async () => {
|
||||
const page = getPageStruct();
|
||||
|
||||
// go to login page and login
|
||||
await browser.get('');
|
||||
await page.loginHref.click();
|
||||
await page.loginButton.click();
|
||||
|
||||
// open secondary outlet
|
||||
await page.contactHref.click();
|
||||
|
||||
// go to login page and logout
|
||||
await page.loginHref.click();
|
||||
await page.loginButton.click();
|
||||
|
||||
// attempt to go to admin page, redirects to login with secondary outlet open
|
||||
await page.adminHref.click();
|
||||
|
||||
// login, get redirected back to admin with outlet still open
|
||||
await page.loginButton.click();
|
||||
|
||||
expect(await page.adminPage.isDisplayed()).toBeTruthy();
|
||||
expect(page.secondaryOutlet.count()).toBeTruthy();
|
||||
});
|
||||
|
||||
async function crisisCenterEdit(index: number, save: boolean) {
|
||||
const page = getPageStruct();
|
||||
await page.crisisHref.click();
|
||||
|
|
|
@ -27,10 +27,10 @@ export class LoginComponent {
|
|||
if (this.authService.isLoggedIn) {
|
||||
// Get the redirect URL from our auth service
|
||||
// If no redirect has been set, use the default
|
||||
let redirect = this.authService.redirectUrl ? this.authService.redirectUrl : '/crisis-center/admin';
|
||||
let redirect = this.authService.redirectUrl ? this.router.parseUrl(this.authService.redirectUrl) : '/admin';
|
||||
|
||||
// Redirect the user
|
||||
this.router.navigate([redirect]);
|
||||
this.router.navigateByUrl(redirect);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ export class LoginComponent {
|
|||
if (this.authService.isLoggedIn) {
|
||||
// Get the redirect URL from our auth service
|
||||
// If no redirect has been set, use the default
|
||||
let redirect = this.authService.redirectUrl ? this.authService.redirectUrl : '/admin';
|
||||
let redirect = this.authService.redirectUrl ? this.router.parseUrl(this.authService.redirectUrl) : '/admin';
|
||||
|
||||
// #docregion preserve
|
||||
// Set our navigation extras object
|
||||
|
@ -39,7 +39,7 @@ export class LoginComponent {
|
|||
};
|
||||
|
||||
// Redirect the user
|
||||
this.router.navigate([redirect], navigationExtras);
|
||||
this.router.navigateByUrl(redirect, navigationExtras);
|
||||
// #enddocregion preserve
|
||||
}
|
||||
});
|
||||
|
|
|
@ -3849,7 +3849,7 @@ Update the `AuthGuard` to provide a `session_id` query that will remain after na
|
|||
|
||||
Add an `anchor` element so you can jump to a certain point on the page.
|
||||
|
||||
Add the `NavigationExtras` object to the `router.navigate` method that navigates you to the `/login` route.
|
||||
Add the `NavigationExtras` object to the `router.navigate()` method that navigates you to the `/login` route.
|
||||
|
||||
|
||||
<code-example path="router/src/app/auth/auth.guard.4.ts" linenums="false" header="src/app/auth/auth.guard.ts (v3)">
|
||||
|
@ -3860,7 +3860,7 @@ Add the `NavigationExtras` object to the `router.navigate` method that navigates
|
|||
|
||||
You can also preserve query parameters and fragments across navigations without having to provide them
|
||||
again when navigating. In the `LoginComponent`, you'll add an *object* as the
|
||||
second argument in the `router.navigate` function
|
||||
second argument in the `router.navigateUrl()` function
|
||||
and provide the `queryParamsHandling` and `preserveFragment` to pass along the current query parameters
|
||||
and fragment to the next route.
|
||||
|
||||
|
|
Loading…
Reference in New Issue