本文整理汇总了TypeScript中@angular/router.Router.navigateByUrl方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Router.navigateByUrl方法的具体用法?TypeScript Router.navigateByUrl怎么用?TypeScript Router.navigateByUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/router.Router
的用法示例。
在下文中一共展示了Router.navigateByUrl方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: handleError
private handleError(error: any) {
let errorMessage: any;
if (error instanceof HttpErrorResponse) {
if (error.status === 401 || error.status === 403) {
this.router.navigateByUrl('');
this.sms.displayErrorMessage('You are not authenticated to access that page');
}
errorMessage = error.error || JSON.stringify(error);
if (errorMessage.error) {
errorMessage = errorMessage.error;
}
errorMessage = `${error.status} - ${error.statusText || ''}: ${errorMessage}`;
} else {
errorMessage = error.message ? error.message : error.toString();
}
return throwError(errorMessage);
}
示例2: goTo
goTo(url: string) {
if (this.order.billing.name &&
this.order.billing.email &&
this.order.billing.address &&
this.order.billing.city &&
this.order.billing.state &&
this.order.billing.zip) {
this.globalService.order.next(this.order);
this.router.navigateByUrl(url);
this.localCart.orderUpdateItems(this.order);
} else {
let snackBarRef = this.snackBar.open('You must complete the form', 'OK!', {
duration: 3000,
extraClasses: ['warn-snackbar']
});
}
}
示例3: handleEnter
// ---
// PUBLIC METHODS.
// ---
// I navigate to the first item in the filtered list.
public handleEnter() : void {
var project = this.filteredProjects.find(
( filteredProject: FilteredProject ) : boolean => {
return( filteredProject.isVisible );
}
);
if ( project ) {
this.router.navigateByUrl( project.resource );
}
}
示例4: canActivate
// ---
// PUBLIC METHODS.
// ---
// I determine if the requested route can be activated (ie, navigated to).
public canActivate(
activatedRouteSnapshot: ActivatedRouteSnapshot,
routerStateSnapshot: RouterStateSnapshot
) : boolean {
// We don't want this modal to show on page-refresh. As such, if this is a page-
// refresh, we'll navigate to the same URL less the modal outlet.
if ( this.isPageRefresh() ) {
this.router.navigateByUrl( this.getUrlWithoutModal( routerStateSnapshot ) );
return( false );
}
return( true );
}
示例5: constructor
constructor(
public snackBar: MdSnackBar,
public router: Router,
public globalService: GlobalService,
public localCart: LocalCartService,
private title: Title,
private meta: Meta
) {
this.states = globalService.states;
this.order = globalService.order.getValue();
if (!this.order.shipping) {
router.navigateByUrl('cart');
}
if (this.localCart.orderHasItems() && this.localCart.orderHas('billing')) {
this.order = this.localCart.orderGetItems();
}
}
示例6: User
data => {
if (data['error']) {
this.loading = false;
this.message = {
type: 'danger',
message: data['message']
};
}else {
let user = Object.assign(new User(), data['user']);
user.token = data['token'];
user.role = user.role.id;
user.isLogged = true;
this.store.dispatch({type: SET_VALIDATE_TOKEN, payload: true});
this.store.dispatch({type: SET_USER, payload: user});
this.router.navigateByUrl('dashboard/subscriber_project/general');
}
}, err => {
示例7:
_router.events.subscribe( e=>{
console.log( e );
if( e instanceof NavigationStart ){
console.log("starting navigation.");
}
if( e instanceof NavigationEnd ) {
console.log("ending navigation.");
}
if( e instanceof NavigationError ) {
let lowerCaseUrl = e.url.toLowerCase();
this._router.navigateByUrl( lowerCaseUrl);
}
})
示例8:
}, (err: any) => {
if (err instanceof HttpErrorResponse) {
if (err.status === 401) {
// TODO: Add information about unAuthorized to user and redirect user.
console.log('We intercepted a 401 boys!!!');
}
if (err.status === 404) {
console.log(err.url);
console.log('We intercepted a 404 boys!!!');
const role = localStorage.getItem('Role');
console.log(role);
if (role === 'Group' && err.url.includes('contracts')) {
console.log('Redirecting to newContract');
this.router.navigateByUrl('contracts/newContract');
}
}
}
});
示例9: expect
.then((_) => {
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
if (ev.startsWith('deactivate')) {
completer.resolve(true);
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('parent {deactivate cmp}');
}
});
rtr.navigateByUrl('/a').then((_) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('A');
expect(log).toEqual([
'deactivate: /child-deactivate -> null',
'parent deactivate: /parent-deactivate -> /a'
]);
async.done();
});
});
示例10: canActivate
// ---
// PUBLIC METHODS.
// ---
// I determine if the requested route can be activated (ie, navigated to).
public canActivate(
activatedRouteSnapshot: ActivatedRouteSnapshot,
routerStateSnapshot: RouterStateSnapshot
) : boolean {
// We don't want to render this secondary view on page-refresh. As such, if this
// is a page-refresh, we'll navigate to the same URL less the secondary outlet.
if ( this.isPageRefresh() ) {
console.warn( "Secondary view not allowed on refresh." );
this.router.navigateByUrl( this.getUrlWithoutSecondary( routerStateSnapshot ) );
return( false );
}
return( true );
}