使用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' },
应处理未指定的任何路由。
I am having an issue regarding routing on my live website. Locally the routing works fine but when a user refreshes the page a 404 error is thrown and the same happens when a user clicks on a link that takes them to an external website and they press the back button. I am familiar with angular but this is my first time hosting a website.
Here is my app-routing.module.ts code:
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 { }
I'm not sure which part of the routing I am misunderstanding because the:
{ path: '', redirectTo: 'landing', pathMatch: 'full' },
should handle any route that is not specified.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您自己托管了一个Angular应用程序,则您的服务器可能需要配置来重新启动URL。他们在文档中有一个部分:
https://angular.io/guide/guide/guide/deployment#服务器 - 配置
有几种指南各种类型的指南。
Your server likely needs configuration to remap urls if you're hosting an angular application on your own. They have a section about this in the documentation:
https://angular.io/guide/deployment#server-configuration
With a few guides on various types.