【发布时间】:2020-12-21 12:59:30
【问题描述】:
将 Angular 2 RC 4 与更新的 @angular/router 一起使用,我使用 this question 中的答案将路由 URL 显示在浏览器中
但是,当我刷新或直接请求具有非默认路由的页面时,它会将我带到默认页面(就像我请求 index.html)而不是我想要的路由页面。如何使 Angular 2 路由在使用 Apache 2.4 刷新页面时正常工作?
路线和引导程序:
const routes: RouterConfig = [
{ path: '', redirectTo: 'dashboardTab', terminal: true },
{ path: 'dashboardTab', component: DashboardComponent },
{ path: 'missionTab', component: MissionComponent, children: childRoutes }];
bootstrap(NavbarComponent, [disableDeprecatedForms(), provideForms(), provideRouter(routes), {provide: Window, useValue: window}, HTTP_PROVIDERS, ResponsiveState, {provide: PLATFORM_DIRECTIVES, useValue: RESPONSIVE_DIRECTIVES, multi: true}]).catch((err: any) => console.error(err));
index.html 中的基本 href:
<base href="/">
【问题讨论】:
-
请展示一些代码来演示您要完成的工作。路由,
<base>标记在index.html,bootstrap(...),... -
@GünterZöchbauer 完成。我最初并不认为添加代码是相关的,尽管当我在 lite-server 上运行我的代码时页面刷新路由有效。它似乎在我的 Apache 服务器上不起作用。
-
terminal: true在最新版本中应为pathMatch: 'full'。如果它使用 lite-server 而不是 Apache 运行,那么您的 Apache 未配置为支持 HTML5 pushState。您可以尝试切换到HashLocationStrategy进行验证。如果可行,则说明是服务器配置问题。
标签: apache angular angular2-routing