我的Angular应用程序的路由器有问题。我正在提供一个应用程序,并将其部署在Apache服务器的生产环境中。我从URL www.domain.com/clientng 提供服务,并且可以正常运行,但是例如当我尝试访问 www.domain.com/clientng/home 时,浏览器控制台显示此错误。
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'clientng' Error: Cannot match any routes. URL Segment: 'clientng'
我的路由器配置为:
const appRoutes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'home', component: HomeComponent },
{ path: 'autologin', component: AutoLoginComponent },
{ path: 'forbidden', component: ForbiddenComponent },
{ path: 'unauthorized', component: UnauthorizedComponent },
];
在编译应用程序时,我使用--base-href "/ clientng /"
进行操作,因此索引已正确标记了文档的来源。
Apache DocumentRoot位于/home/user/appweb
,而角度应用程序则部署在/home/user/appweb/clientng
我不知道发生了什么,因为页面显示正确,并且应用程序运行良好,但是控制台显示了该错误。
答案 0 :(得分:0)
应用程序路由模块
const routes: Routes = [
{
path: '', component: LayoutsComponent,
children: [
// { path: 'clienting', loadChildren: './components/clienting/clienting.module#ClientingModule'} ,
{ path: 'clienting', loadChildren: () => import('./components/clienting/clienting.module').then(m => m.ClientingModule) },
....
然后在您的客户端模块中
使用您的代码
const appRoutes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'home', component: HomeComponent },
{ path: 'autologin', component: AutoLoginComponent },
{ path: 'forbidden', component: ForbiddenComponent },
{ path: 'unauthorized', component: UnauthorizedComponent },
];
答案 1 :(得分:0)
您的路由实现需要定义完全匹配的路由:
const appRoutes: Routes = [
{
path: '',
redirectTo: "/home",
pathMatch: 'full'
},
{ path: 'home', component: HomeComponent },
{ path: 'autologin', component: AutoLoginComponent },
{ path: 'forbidden', component: ForbiddenComponent },
{ path: 'unauthorized', component: UnauthorizedComponent },
];