[英]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这是我的项目结构
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在应用程序路由模块中,我的登录页面是直接打开的(意味着它是我的第一页)然后我需要点击登录按钮,我需要显示仪表板/电子商务,但不知道为什么显示错误
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).从您的代码中,我看不出路径
/dashboard/eCommerce
如何存在的,因为在某处没有提到仪表板(除了通过模块名称隐式地提到)。
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'
}
},
]
}
];
Try this:尝试这个:
login(){
this.router.navigate(['/eCommerce']);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.