---
title: "How do you redirect to a URL in Angular?"
description: "Use Router.navigate for routes inside the app, window.location for external URLs, redirectTo in the route table, and a guard that returns a UrlTree."
url: "https://bugsee.com/answers/ionic/angular-redirect-to-url/"
---

# How do you redirect to a URL in Angular?

For a route in your app call `router.navigateByUrl('/home')`; for another website set `window.location.href`. A route-table `redirectTo` handles fixed redirects.

```typescript
import { Component, inject } from '@angular/core';
import { Router, Routes, CanActivateFn } from '@angular/router';

@Component({ selector: 'app-login', template: '' })
export class LoginComponent {
  private router = inject(Router);

  done() {
    this.router.navigateByUrl('/home');               // inside the app
    this.router.navigate(['/items', 42], { queryParams: { tab: 'info' } });
  }

  openDocs() {
    window.location.href = 'https://example.com/docs'; // external site
  }
}

// Fixed redirect in the route table
export const routes: Routes = [
  { path: '', redirectTo: 'home', pathMatch: 'full' },
  { path: 'home', loadComponent: () => import('./home.page').then(m => m.HomePage) },
];

// Redirect from a guard
export const authGuard: CanActivateFn = () =>
  inject(AuthService).loggedIn() || inject(Router).createUrlTree(['/login']);
```

In Ionic apps, `NavController.navigateRoot('/home')` also resets the back stack, which suits a post-login redirect.

## Related questions

- [How do you set a default route in Ionic React with React Router?](https://bugsee.com/answers/ionic/react-router-default-route/)
