angular - 角度路由网址问题
问题描述
我只是在练习路由。我只想在点击时显示显示页面,但显示错误
Error: Cannot match any routes. URL Segment: 'dashboard/eCommerce'
这是我的项目结构
在登录页面上,我使用点击功能来显示这样的其他页面
login(){
this.router.navigate(['/dashboard/eCommerce']);
}
仪表板路由模块
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 {
}
在应用程序路由模块中,我的登录页面直接打开(意味着它是我的第一页)然后我需要点击登录按钮我需要显示仪表板/电子商务但不知道为什么它显示错误
解决方案
从您的代码中,我看不到路径是如何/dashboard/eCommerce
存在的,因为在某处未提及仪表板(通过模块名称隐含地除外)。
你可能想要这个:
const routes: Routes = [
{
// This would define the path to be named 'dashboard'.
path: 'dashboard',
children: [
{
path: 'eCommerce',
component: EcommerceComponent,
data: {
title: 'eCommerce'
}
},
]
}
];
推荐阅读
- html - 无法让引导下拉菜单离线处理本地文件
- nuxt.js - 'nuxt-link' 重定向到生产服务器和本地服务器中的不同地址
- google-cloud-platform - 如何在 Google Cloud 请求中设置最大接收消息长度?
- c# - C# 中基于距离的价格计算
- ios - 使用来自 Web 服务的更新数据(包括关系)更新核心数据
- reactjs - ReactJS 中图片的相对路径
- javascript - 为什么节点 https 模块文档示例将 tls 选项同时传递给代理和请求选项?
- flutter - 颤振统一小部件是否适用于统一 2d?
- javascript - 仅获取具有两个特定类的 div
- python - 修改 dtypes 的输出