Hello, I am trying to change the default redirect in an Angular 2 app. It is not working. I changed the app-routing.module.ts to something like this:
'/poc' is a route defined inside the 'sms' module as shown below.
Why would it not work?
Thanks
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { NotificationsComponent } from './shared/layout/notifications/notifications.component';
import { AppComponent } from './app.component';
import { AppRouteGuard } from './shared/common/auth/auth-route-guard';
@NgModule({
imports: [
RouterModule.forChild([
{
path: 'app',
component: AppComponent,
canActivate: [AppRouteGuard],
canActivateChild: [AppRouteGuard],
children: [
{
path: '',
children: [
{ path: 'notifications', component: NotificationsComponent },
{ path: '', redirectTo: '/poc', pathMatch: 'full' }
]
},
{
path: 'main',
loadChildren: 'app/main/main.module#MainModule', //Lazy load main module
data: { preload: true }
},
{
path: 'admin',
loadChildren: 'app/admin/admin.module#AdminModule', //Lazy load admin module
data: { preload: true }
},
{
path: 'sms',
loadChildren: 'app/sms/sms.module#SmsModule', //Lazy load sms module
data: { preload: true }
}
]
}
])
],
exports: [RouterModule]
})
export class AppRoutingModule { }
6 Answer(s)
-
0
Hi,
Sorry for the late reply. You can modify this function to change default route <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/dev/angular/src/app/shared/common/auth/auth-route-guard.ts#L43">https://github.com/aspnetzero/aspnet-ze ... ard.ts#L43</a>.
Thanks.
-
0
Thanks Ismail.
Im fact, I am not yet getting why the need for this function in a time canActivate is doing the job? Can you illustrate more please?
Isn't better to keep the default Angular 2 routing?
-
0
Hi @bilalhaidar,
I don't know how I can tell you more than this :). Your main request was changing the default redirect route and you can do it by changing auth-route-guard.ts file.
-
0
Hahaha thanks Ismail. I meant from my question why not count only on the canActivate why need that function to redirect. That's my point. Isnt it duplicating the checking?
-
0
Hi @bilalhaidar,
I think this was the case but I don't remember very well. When a user navigates to a route that user does not have permission, we wanted to redirect user to a default page that he/she has access to. I think this is not possible with default behaviour.
-
0
Good to know. Thanks a lot