Angular 2,如何在直接访问www.example.com/otherURL时重定向到www.example.com的库

时间:2018-08-04 04:12:13

标签: angular angular2-routing

我敢肯定这已经被问过了,但是我不知道我应该寻找什么信息,并且特定于Angular的示例似乎很少。

我正在使用一个网站,正在使用/学习Angular 2。

这里是:https://stuart-aitken.tk/

问题是,如果我直接导​​航到该网站的任何主页,例如https://stuart-aitken.tk/home,则会出现404错误。

在本地主机的测试环境中运行它时,它工作正常。

不确定在这里我做错了什么。当我在控制台中构建站点时,我像这样指定了基本URL:

ng build --prod --base-href="https://stuart-aitken.tk/"

app.module.ts中的RouterModule看起来像这样:

imports: [ BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }), BrowserAnimationsModule, RouterModule.forRoot( [ { path: 'home', component: HomeComponent, pathMatch: 'full' }, { path: 'programming', component: ProgrammingComponent, pathMatch: 'full' }, { path: '**', redirectTo: 'home', pathMatch: 'full' } ]), NgbModule.forRoot(), ]

此外,在index.html中,我在<base href="/">区域中有<head>

还有什么我应该知道的或者做错了吗?

我对解决方案的第一个想法是只告诉我的Web托管提供商将所有扩展URL重定向到我网站的主页,但是我感觉这在Angular世界中是一件非常错误的事情。但老实说,我只是不知道。

任何帮助,不胜感激!

0 个答案:

没有答案