直接导航到角度4中的URL

时间:2018-09-26 17:09:03

标签: angular routes

我正在尝试使用www.domain.com/demolink导航到演示页面,但我却被丢给了一个错误处理程序。但是,如果我在<a routerLink="/demolink">QT Demo Link</a>上创建www.domain.com routerLink,则可以导航到Demo页面。

我的应用路线如下

export const appRoutes: Routes = [
  {path: '', component: LoginComponent},
  {path: 'demolink', component:QtDemoLoginComponent},
  {path: 'login', component: LoginComponent},
  {path: 'app/:errorCode', component: AppComponent},
  {path: 'errorHandler', component: ErrorViewComponent},
  {path: '**', component: ErrorViewComponent}
];

怎么了?请指教。

1 个答案:

答案 0 :(得分:1)

您可能需要将服务器设置为在找不到资源时回退到index.html,以便Angular路由器可以处理请求。 The Angular docs mention this in the section on deployment

在我的Apache virtualhost文件中,我使用FallbackResource

FallbackResource /index.html

,并且有效。您也可以使用重写规则,但这很短而且很容易理解。