Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(router-outlet): getRouteId() method now returns parameters #24656

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2243,7 +2243,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<boolean>;
Expand Down Expand Up @@ -5914,7 +5914,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;
Expand Down
10 changes: 5 additions & 5 deletions core/src/components/router-outlet/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)` |


----------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions core/src/components/router-outlet/route-outlet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class RouterOutlet implements ComponentInterface, NavOutlet {

private activeEl: HTMLElement | undefined;
private activeComponent: any;
private activeParams: any;
private waitPromise?: Promise<void>;
private gesture?: Gesture;
private ani?: Animation;
Expand All @@ -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 */
Expand Down Expand Up @@ -156,6 +154,7 @@ export class RouterOutlet implements ComponentInterface, NavOutlet {
return active ? {
id: active.tagName,
element: active,
params: this.activeParams,
} : undefined;
}

Expand All @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions core/src/components/router-outlet/test/basic/e2e.ts
Original file line number Diff line number Diff line change
@@ -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' });
});
18 changes: 8 additions & 10 deletions core/src/components/router-outlet/test/basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ion-header>
<ion-content class="ion-padding">
<h1>Page One</h1>
<ion-button href="#/two">Go to Page Two</ion-button>
<ion-button href="#/two/segment">Go to Page Two</ion-button>
</ion-content>
`;
}
Expand All @@ -30,17 +30,14 @@ <h1>Page One</h1>
this.innerHTML = `
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button text="Page One"></ion-back-button>
</ion-buttons>
<ion-title>Page Two</ion-title>
</ion-toolbar>
</ion-header>
<ion-content class="ion-padding">
<h1>Page Two</h1>
<div>
<ion-nav-link router-direction="forward" component="page-three">
<ion-button href="#/page-3">Go to Page Two</ion-button>
<ion-button href="#/page-3">Go to Page Three</ion-button>
</ion-nav-link>
</div>
</ion-content>
Expand All @@ -52,9 +49,6 @@ <h1>Page Two</h1>
this.innerHTML = `
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button text="Page Two"></ion-back-button>
</ion-buttons>
<ion-title>Page Three</ion-title>
</ion-toolbar>
</ion-header>
Expand All @@ -74,7 +68,7 @@ <h1>Page Three</h1>
<ion-app>
<ion-router>
<ion-route url="/" component="page-one"> </ion-route>
<ion-route url="/two" component="page-two"> </ion-route>
<ion-route url="/two/:param" component="page-two"> </ion-route>
<ion-route url="/page-3" component="page-three"> </ion-route>
</ion-router>

Expand All @@ -89,7 +83,7 @@ <h1>Page Three</h1>
<ion-item href="#/">
<ion-label>Page 1</ion-label>
</ion-item>
<ion-item href="#/two">
<ion-item href="#/two/segment">
<ion-label>Page 2</ion-label>
</ion-item>
<ion-item href="#/page-3">
Expand All @@ -102,4 +96,8 @@ <h1>Page Three</h1>
</ion-app>
</body>

<script>
document.querySelector('ion-route[component=page-three]').componentProps = {param: "route"};
</script>

</html>