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

Change return signature of router navigate() and navigateToRoute() from boolean to NavigationResult #650

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion dist/amd/aurelia-router.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/aurelia-router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export declare class Router {
* @param fragment The URL fragment to use as the navigation destination.
* @param options The navigation options.
*/
navigate(fragment: string, options?: NavigationOptions): boolean;
navigate(fragment: string, options?: NavigationOptions): NavigationResult;
/**
* Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed
* by [[Router.navigate]].
Expand All @@ -297,7 +297,7 @@ export declare class Router {
* @param params The route parameters to be used when populating the route pattern.
* @param options The navigation options.
*/
navigateToRoute(route: string, params?: any, options?: NavigationOptions): boolean;
navigateToRoute(route: string, params?: any, options?: NavigationOptions): NavigationResult;
/**
* Navigates back to the most recent location in history.
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/commonjs/aurelia-router.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/es2015/aurelia-router.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/native-modules/aurelia-router.js.map

Large diffs are not rendered by default.

41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
_createRootedPath,
_resolveUrl
} from './util';
import { RouteConfig, RouteConfigSpecifier, ViewPortInstruction } from './interfaces';
import { NavigationResult, RouteConfig, RouteConfigSpecifier, ViewPortInstruction } from './interfaces';
import { PipelineProvider } from './pipeline-provider';

/**@internal */
Expand Down Expand Up @@ -293,7 +293,7 @@ export class Router {
* @param fragment The URL fragment to use as the navigation destination.
* @param options The navigation options.
*/
navigate(fragment: string, options?: NavigationOptions): boolean {
navigate(fragment: string, options?: NavigationOptions): NavigationResult {
if (!this.isConfigured && this.parent) {
return this.parent.navigate(fragment, options);
}
Expand All @@ -310,7 +310,7 @@ export class Router {
* @param params The route parameters to be used when populating the route pattern.
* @param options The navigation options.
*/
navigateToRoute(route: string, params?: any, options?: NavigationOptions): boolean {
navigateToRoute(route: string, params?: any, options?: NavigationOptions): NavigationResult {
matthewcorven marked this conversation as resolved.
Show resolved Hide resolved
let path = this.generate(route, params);
return this.navigate(path, options);
}
Expand Down
36 changes: 36 additions & 0 deletions test/router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ describe('the router', () => {
});

describe('navigate', () => {
const delay = (milliseconds: number) => new Promise(res => setTimeout(res, milliseconds));

it('should navigate to absolute paths', (done) => {
const options = {};
spyOn(history, 'navigate');
Expand Down Expand Up @@ -230,6 +232,40 @@ describe('the router', () => {
done();
});
});

it('should return to caller immediately if not awaited', (done) => {
matthewcorven marked this conversation as resolved.
Show resolved Hide resolved
const options = {};
let navigationPending = false;
spyOn(history, 'navigate').and.callFake(async () => {
navigationPending = true;
await delay(10);
navigationPending = false;
done();
});

router.configure(config => config.map({ name: 'test', route: 'test/:id', moduleId: './test' }))
.then(() => {
router.navigateToRoute('test', { id: 123 }, options);
expect(navigationPending).toBe(true);
});
});

it('should return to caller after routing complete if awaited', (done) => {
const options = {};
let navigationPending = false;
spyOn(history, 'navigate').and.callFake(async () => {
navigationPending = true;
await delay(10);
navigationPending = false;
});

router.configure(config => config.map({ name: 'test', route: 'test/:id', moduleId: './test' }))
.then(async () => {
await router.navigateToRoute('test', { id: 123 }, options);
expect(navigationPending).toBe(false);
done();
});
});
});

describe('_createNavigationInstruction', () => {
Expand Down