I have interesting problem when using children routes in Angular. The route is only working when there is a redirection to this "non-working" route.
In my browser if I type localhost:4200/customer/add/, the error is 404. But if I type localhost:4200/customer (this route is redirected to customer/add) the page is working.
My routing-module:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Routes, RouterModule } from '@angular/router';
import { AuthenticationLayoutComponent } from '../../components/authentication-layout/authentication-layout.component';
import { LoginComponent } from 'src/app/components/authentication/login/login.component';
import { AddCustomerComponent } from 'src/app/components/customer/add-customer/add-customer.component';
import { RegisterComponent } from 'src/app/components/authentication/register/register.component';
import { MasterLayoutComponent } from 'src/app/components/master-layout/master-layout.component';
const routes: Routes = [
{
path: 'customer',
component: MasterLayoutComponent,
children: [
{ path: "", redirectTo: 'add',pathMatch: 'full' },
{ path: "add", component: AddCustomerComponent},
],
},
{
path: '',
component: AuthenticationLayoutComponent,
children: [
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent },
],
},
];
@NgModule({
declarations: [],
providers: [],
imports: [
CommonModule,
RouterModule.forRoot(routes, { enableTracing: false }),
],
exports: [RouterModule],
})
export class AppRoutingModule {}
Via Active questions tagged javascript - Stack Overflow https://ift.tt/KSX69lL
Comments
Post a Comment