Hi Dev,
In this article, i will let you know how to redirect to another page in angular 8 application. i will show you how redirect to another route in angular 9 application.
in angular, using redirectTo we can easily redirect to another route. i will give you very simple example so you can easily use it.
It's pretty simple to redirect to another route url using redirectTo in angular application. but you maybe don't know so you can simple see bellow app-routing.module.ts file and see how i declare routes and how i redirect that home page to another route.
You can see code of route define:
{
path: '',
redirectTo: 'redirect_route_name',
pathMatch: 'full'
}
you can just see bellow code and you will have solution for your angular app.
app-routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { BlogComponent } from './blog/blog.component';
import { PostsComponent } from './posts/posts.component';
const routes: Routes = [
{
path: '',
redirectTo: 'posts',
pathMatch: 'full'
},
{
path: 'posts',
component: PostsComponent
},
{
path: 'blog/:id',
component: BlogComponent
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
If you run your home page like this way:
http://localhost:4200/
It will redirect to this url:
http://localhost:4200/posts
I hope it can help you...
Do you like below Tutorials ?
- Laravel 7.x and 6.x Ajax Multiple Image Upload with Preview Example
- Laravel select with count(*) using db raw example
- PHP Laravel select with join subquery example
- PHP Laravel Ajax Form Submit Example
- How to create events for created/updated/deleted model task in Laravel 5?
- Angular JS Form Validation Example Code
- AngularJS - Confirm Password Validation Example
- Laravel Ajax Request using X-editable bootstrap Plugin Example