rameez khan
rameez khan

Reputation: 359

Angular routing url issue

I am simply practicing routing. I want to simply show display the page on click but its showing error

Error: Cannot match any routes. URL Segment: 'dashboard/eCommerce'

This is my project structure

enter image description here

On login page i use click function to show the other page like this

login(){
    this.router.navigate(['/dashboard/eCommerce']);
}

dashboard-routing module

    import { NgModule } from '@angular/core';
    import { Routes, RouterModule } from '@angular/router';
    
    import { EcommerceComponent } from "./eCommerce/eCommerce.component";
    
    const routes: Routes = [
      {
        path: '',
        children: [
          {
            path: 'eCommerce',
            component: EcommerceComponent,
            data: {
              title: 'eCommerce'
            }
          },
        ]
      }
    ];
    
    @NgModule({
      imports: [RouterModule.forChild(routes)],
      exports: [RouterModule],
    })
    export class DashboardRoutingModule { }

This is my app-routing module

const appRoutes: Routes = [
  {
    path: '',
    component: LoginPageComponent,
    pathMatch: 'full',
  },

    {
    path: 'register',
    component: RegisterPageComponent,
    pathMatch: 'full',
  },
  { path: '', component: FullLayoutComponent, data: { title: 'full Views' }, children: Full_ROUTES, canActivate: [AuthGuard] },
  { path: '', component: ContentLayoutComponent, data: { title: 'content Views' }, children: CONTENT_ROUTES, canActivate: [AuthGuard] },
];

@NgModule({
  imports: [RouterModule.forRoot(appRoutes)],
  exports: [RouterModule]
})

export class AppRoutingModule {

}

In app-routing module my login page is directly open (mean its my first page) Then i need on button click on login i need to show the dashboard/Ecommerce but don't know why its showing error

Upvotes: 0

Views: 96

Answers (2)

echo martha
echo martha

Reputation: 1

Try this:

      login(){
    this.router.navigate(['/eCommerce']);
}

Upvotes: 0

code-gorilla
code-gorilla

Reputation: 2408

From your code I can't see how the path /dashboard/eCommerce could exist, as dashboard is not mentioned somewhere (except implicitly through the module name).

You probably want this:

const routes: Routes = [
      {
        // This would define the path to be named 'dashboard'.
        path: 'dashboard',
        children: [
          {
            path: 'eCommerce',
            component: EcommerceComponent,
            data: {
              title: 'eCommerce'
            }
          },
        ]
      }
    ];

Upvotes: 1

Related Questions