From be2205e5a2b2f8778bd1f7b4ea5cae0bf96f9ef3 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 9 Feb 2022 10:38:46 -0800 Subject: [PATCH] fix(router-outlet): getRouteId() returns the params set in setRouteId(). (#24656) resolves #24652 --- core/src/components.d.ts | 4 +-- core/src/components/router-outlet/readme.md | 10 +++---- .../components/router-outlet/route-outlet.tsx | 8 ++--- .../router-outlet/test/basic/e2e.ts | 29 +++++++++++++++++++ .../router-outlet/test/basic/index.html | 18 +++++------- 5 files changed, 48 insertions(+), 21 deletions(-) create mode 100644 core/src/components/router-outlet/test/basic/e2e.ts diff --git a/core/src/components.d.ts b/core/src/components.d.ts index b25481da410..c2ef6546f09 100644 --- a/core/src/components.d.ts +++ b/core/src/components.d.ts @@ -2254,7 +2254,7 @@ export namespace Components { */ "animated": boolean; /** - * By default `ion-nav` animates transition between pages based in the mode (ios or material design). However, this property allows to create custom transition using `AnimateBuilder` functions. + * This property allows to create custom transition using AnimateBuilder functions. */ "animation"?: AnimationBuilder; "commit": (enteringEl: HTMLElement, leavingEl: HTMLElement | undefined, opts?: RouterOutletOptions | undefined) => Promise; @@ -5925,7 +5925,7 @@ declare namespace LocalJSX { */ "animated"?: boolean; /** - * By default `ion-nav` animates transition between pages based in the mode (ios or material design). However, this property allows to create custom transition using `AnimateBuilder` functions. + * This property allows to create custom transition using AnimateBuilder functions. */ "animation"?: AnimationBuilder; "delegate"?: FrameworkDelegate; diff --git a/core/src/components/router-outlet/readme.md b/core/src/components/router-outlet/readme.md index 2c6d5917e37..9343749d8ab 100644 --- a/core/src/components/router-outlet/readme.md +++ b/core/src/components/router-outlet/readme.md @@ -30,11 +30,11 @@ For handling Router Guards, the older `ionViewCanEnter` and `ionViewCanLeave` ha ## Properties -| Property | Attribute | Description | Type | Default | -| ----------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | ------------------ | -| `animated` | `animated` | If `true`, the router-outlet should animate the transition of components. | `boolean` | `true` | -| `animation` | -- | By default `ion-nav` animates transition between pages based in the mode (ios or material design). However, this property allows to create custom transition using `AnimateBuilder` functions. | `((baseEl: any, opts?: any) => Animation) \| undefined` | `undefined` | -| `mode` | `mode` | The mode determines which platform styles to use. | `"ios" \| "md"` | `getIonMode(this)` | +| Property | Attribute | Description | Type | Default | +| ----------- | ---------- | -------------------------------------------------------------------------------- | ------------------------------------------------------- | ------------------ | +| `animated` | `animated` | If `true`, the router-outlet should animate the transition of components. | `boolean` | `true` | +| `animation` | -- | This property allows to create custom transition using AnimateBuilder functions. | `((baseEl: any, opts?: any) => Animation) \| undefined` | `undefined` | +| `mode` | `mode` | The mode determines which platform styles to use. | `"ios" \| "md"` | `getIonMode(this)` | ---------------------------------------------- diff --git a/core/src/components/router-outlet/route-outlet.tsx b/core/src/components/router-outlet/route-outlet.tsx index 5e8e036e51e..173662790db 100644 --- a/core/src/components/router-outlet/route-outlet.tsx +++ b/core/src/components/router-outlet/route-outlet.tsx @@ -16,6 +16,7 @@ export class RouterOutlet implements ComponentInterface, NavOutlet { private activeEl: HTMLElement | undefined; private activeComponent: any; + private activeParams: any; private waitPromise?: Promise; private gesture?: Gesture; private ani?: Animation; @@ -36,10 +37,7 @@ export class RouterOutlet implements ComponentInterface, NavOutlet { */ @Prop() animated = true; - /** - * By default `ion-nav` animates transition between pages based in the mode (ios or material design). - * However, this property allows to create custom transition using `AnimateBuilder` functions. - */ + /** This property allows to create custom transition using AnimateBuilder functions. */ @Prop() animation?: AnimationBuilder; /** @internal */ @@ -156,6 +154,7 @@ export class RouterOutlet implements ComponentInterface, NavOutlet { return active ? { id: active.tagName, element: active, + params: this.activeParams, } : undefined; } @@ -170,6 +169,7 @@ export class RouterOutlet implements ComponentInterface, NavOutlet { this.activeComponent = component; this.activeEl = enteringEl; + this.activeParams = params; // commit animation await this.commit(enteringEl, leavingEl, opts); diff --git a/core/src/components/router-outlet/test/basic/e2e.ts b/core/src/components/router-outlet/test/basic/e2e.ts new file mode 100644 index 00000000000..f58b8af2002 --- /dev/null +++ b/core/src/components/router-outlet/test/basic/e2e.ts @@ -0,0 +1,29 @@ +import { newE2EPage } from '@stencil/core/testing'; + +test('getRouteId() should return the segment parameters', async () => { + const page = await newE2EPage({ + url: '/src/components/router-outlet/test/basic?ionic:_testing=true' + }); + + + await page.$eval('ion-item[href="#/two/segment"] ion-label', (el: any) => el.click()); + await page.waitForChanges(); + const routeId = await page.$eval('ion-router-outlet', async (el: any) => await el.getRouteId()); + + expect(routeId.id).toEqual('PAGE-TWO'); + expect(routeId.params).toEqual({ param: 'segment' }); +}); + +test('getRouteId() should return the route parameters', async () => { + const page = await newE2EPage({ + url: '/src/components/router-outlet/test/basic?ionic:_testing=true' + }); + + + await page.$eval('ion-item[href="#/page-3"] ion-label', (el: any) => el.click()); + await page.waitForChanges(); + const routeId = await page.$eval('ion-router-outlet', async (el: any) => await el.getRouteId()); + + expect(routeId.id).toEqual('PAGE-THREE'); + expect(routeId.params).toEqual({ param: 'route' }); +}); \ No newline at end of file diff --git a/core/src/components/router-outlet/test/basic/index.html b/core/src/components/router-outlet/test/basic/index.html index 2993e033205..d952829b129 100644 --- a/core/src/components/router-outlet/test/basic/index.html +++ b/core/src/components/router-outlet/test/basic/index.html @@ -20,7 +20,7 @@

Page One

- Go to Page Two + Go to Page Two
`; } @@ -30,9 +30,6 @@

Page One

this.innerHTML = ` - - - Page Two @@ -40,7 +37,7 @@

Page One

Page Two

- Go to Page Two + Go to Page Three
@@ -52,9 +49,6 @@

Page Two

this.innerHTML = ` - - - Page Three @@ -74,7 +68,7 @@

Page Three

- + @@ -89,7 +83,7 @@

Page Three

Page 1 - + Page 2 @@ -102,4 +96,8 @@

Page Three

+ +