mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
6
core/src/components.d.ts
vendored
6
core/src/components.d.ts
vendored
@ -2197,11 +2197,11 @@ export namespace Components {
|
|||||||
"navChanged": (direction: RouterDirection) => Promise<boolean>;
|
"navChanged": (direction: RouterDirection) => Promise<boolean>;
|
||||||
"printDebug": () => Promise<void>;
|
"printDebug": () => Promise<void>;
|
||||||
/**
|
/**
|
||||||
* Navigate to the specified URL.
|
* Navigate to the specified path.
|
||||||
* @param url The url to navigate to.
|
* @param path The path to navigate to.
|
||||||
* @param direction The direction of the animation. Defaults to `"forward"`.
|
* @param direction The direction of the animation. Defaults to `"forward"`.
|
||||||
*/
|
*/
|
||||||
"push": (url: string, direction?: RouterDirection, animation?: AnimationBuilder | undefined) => Promise<boolean>;
|
"push": (path: string, direction?: RouterDirection, animation?: AnimationBuilder | undefined) => Promise<boolean>;
|
||||||
/**
|
/**
|
||||||
* The root path to use when matching URLs. By default, this is set to "/", but you can specify an alternate prefix for all URL paths.
|
* The root path to use when matching URLs. By default, this is set to "/", but you can specify an alternate prefix for all URL paths.
|
||||||
*/
|
*/
|
||||||
|
@ -100,9 +100,9 @@ Type: `Promise<void>`
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
### `push(url: string, direction?: RouterDirection, animation?: AnimationBuilder | undefined) => Promise<boolean>`
|
### `push(path: string, direction?: RouterDirection, animation?: AnimationBuilder | undefined) => Promise<boolean>`
|
||||||
|
|
||||||
Navigate to the specified URL.
|
Navigate to the specified path.
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
|
@ -117,18 +117,21 @@ export class Router implements ComponentInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigate to the specified URL.
|
* Navigate to the specified path.
|
||||||
*
|
*
|
||||||
* @param url The url to navigate to.
|
* @param path The path to navigate to.
|
||||||
* @param direction The direction of the animation. Defaults to `"forward"`.
|
* @param direction The direction of the animation. Defaults to `"forward"`.
|
||||||
*/
|
*/
|
||||||
@Method()
|
@Method()
|
||||||
async push(url: string, direction: RouterDirection = 'forward', animation?: AnimationBuilder) {
|
async push(path: string, direction: RouterDirection = 'forward', animation?: AnimationBuilder) {
|
||||||
if (url.startsWith('.')) {
|
if (path.startsWith('.')) {
|
||||||
url = (new URL(url, window.location.href)).pathname;
|
const currentPath = this.previousPath ?? '/';
|
||||||
|
// Convert currentPath to an URL by pre-pending a protocol and a host to resolve the relative path.
|
||||||
|
const url = new URL(path, `https://host/${currentPath}`);
|
||||||
|
path = url.pathname + url.search;
|
||||||
}
|
}
|
||||||
|
|
||||||
let parsedPath = parsePath(url);
|
let parsedPath = parsePath(path);
|
||||||
|
|
||||||
const canProceed = await this.runGuards(parsedPath.segments);
|
const canProceed = await this.runGuards(parsedPath.segments);
|
||||||
if (canProceed !== true) {
|
if (canProceed !== true) {
|
||||||
|
@ -57,6 +57,8 @@
|
|||||||
<p><a href='#/two/three/hello'>Go to page 3 (hello)</a></p>
|
<p><a href='#/two/three/hello'>Go to page 3 (hello)</a></p>
|
||||||
<p><a href='#/two/second-page'>Go to page 2</a></p>
|
<p><a href='#/two/second-page'>Go to page 2</a></p>
|
||||||
<p><a href='#/two/'>Go to page 1</a></p>
|
<p><a href='#/two/'>Go to page 1</a></p>
|
||||||
|
<ion-button id="btn-rel" href="./relative?param=1">Page 3 (relative)</ion-button>
|
||||||
|
<ion-button id="btn-abs" href="/two/three/absolute">Page 3 (absolute)</ion-button>
|
||||||
</ion-content>`;
|
</ion-content>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
29
core/src/components/router/test/basic/router-push.e2e.ts
Normal file
29
core/src/components/router/test/basic/router-push.e2e.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { newE2EPage } from '@stencil/core/testing';
|
||||||
|
|
||||||
|
test('push should support relative path', async () => {
|
||||||
|
const page = await newE2EPage({
|
||||||
|
url: '/src/components/router/test/basic#/two/three/hola?ionic:_testing=true'
|
||||||
|
});
|
||||||
|
await page.waitForChanges();
|
||||||
|
|
||||||
|
const backButton = await page.$('#btn-rel');
|
||||||
|
await backButton.click();
|
||||||
|
await page.waitForChanges();
|
||||||
|
|
||||||
|
const url = await page.url();
|
||||||
|
expect(url).toContain('#/two/three/relative?param=1');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('push should support absolute path', async () => {
|
||||||
|
const page = await newE2EPage({
|
||||||
|
url: '/src/components/router/test/basic#/two/three/hola?ionic:_testing=true'
|
||||||
|
});
|
||||||
|
await page.waitForChanges();
|
||||||
|
|
||||||
|
const backButton = await page.$('#btn-abs');
|
||||||
|
await backButton.click();
|
||||||
|
await page.waitForChanges();
|
||||||
|
|
||||||
|
const url = await page.url();
|
||||||
|
expect(url).toContain('#/two/three/absolute');
|
||||||
|
});
|
Reference in New Issue
Block a user