使用Angular 13的托管网站的路由问题



我在我的现场网站上有一个关于路由的问题。本地路由工作得很好,但当用户刷新页面时抛出404错误,当用户点击将他们带到外部网站的链接并按下后退按钮时也会发生同样的情况。我很熟悉angular,但这是我第一次托管网站。

这是我的app-routing.module。ts代码:

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { BodyComponent } from './body/body.component';
import { LandingPageComponent } from './landing-page/landing-page.component';
const routes: Routes = [
{ path: '', redirectTo: 'landing', pathMatch: 'full' },
{ path: 'dragonevolution', component: BodyComponent },
{ path: 'landing', component: LandingPageComponent },
];
@NgModule({
imports: [
RouterModule.forRoot(routes, {
scrollPositionRestoration: 'enabled',
anchorScrolling: 'enabled',
scrollOffset: [0, 64] // [x, y]
})
],
exports: [RouterModule]
})
export class AppRoutingModule { }

我不确定我误解了路由的哪一部分,因为:

{ path: '', redirectTo: 'landing', pathMatch: 'full' },

应该处理任何未指定的路由。

如果你自己托管一个angular应用程序,你的服务器可能需要配置来重新映射url。他们在文档中有关于这个的章节:

https://angular.io/guide/deployment服务器配置

有一些不同类型的指南。

最新更新