我的角度计划有问题。在dev (ng )中正常工作,按下F5键后,页面重新加载正确,工作正常。
当我构建项目并将项目部署到远程服务器时,一切正常,但按下F5按钮后,页面重新加载并显示错误404 --找不到。我做错什么了?
我的路由器模块:
const routes: Routes = [
// hlavní cesty routingu
{ path: "login", component: LoginComponent },
{ path: "registration", component: RegisterComponent },
{ path: "resetPassword", component: ResetPasswordComponent },
{ path: "resetPasswordNew", component: InsertNewPasswordComponent },
{path: "system",
component: MainComponentComponent,
canActivate: [AuthGuard], // Auth guard mi vrací true nebo false podle toho, zda už mám načtený token nebo ne
children: [
{ path: 'dashboard', component: DashboardComponent, canActivate: [RoleGuardService]}, //RoleGuardService mi hlídá, zda je lognutý žák nebo učitel
{ path: 'baterie' , component: BaterieComponent},
{ path: 'settings' , component: SettingsComponent,
children: [
{path: 'info' , component: InfoComponent, canActivate: [RoleGuardService]}
]
},
{ path: '', redirectTo: 'dashboard', pathMatch: 'full', },
]
},
{ path: '', redirectTo: 'login', pathMatch: 'full', },
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }谢谢!
发布于 2020-05-07 09:02:02
你应该读角部署文档。
路由应用程序必须退回到
index.html对于使用简单的静态HTML服务器,角应用程序是完美的候选程序。您不需要服务器端引擎来动态地组合应用程序页面,因为Angular会在客户端这样做。 如果应用程序使用的是角路由器,则必须配置服务器,以便在请求它没有的文件时返回应用程序的主机页(index.html)。 路由应用程序应该支持“深度链接”。深层链接是一个URL,它指定到应用程序内部组件的路径。例如,http://example.com/heroes/42是一个指向英雄详细信息页面的深度链接,该页面用id: 42显示英雄。 当用户从运行中的客户端导航到该URL时,没有问题。角路由器解释URL和路由到该页面和英雄。 但是,单击电子邮件中的链接,在浏览器地址栏中输入链接,或者在英雄详细信息页面上刷新浏览器,所有这些操作都由浏览器自己处理,在运行中的应用程序之外。浏览器绕过路由器向服务器直接请求该URL。 静态服务器在接收到对index.html的请求时通常返回http://example.com/。但是它拒绝http://example.com/heroes/42并返回一个404 -不是找到的错误,除非它被配置为返回index.html。
https://stackoverflow.com/questions/61652955
复制相似问题