gpt4 book ai didi

angular - 将 Angular 7 部署到 github 页面

转载 作者:行者123 更新时间:2023-12-02 20:11:05 25 4
gpt4 key购买 nike

我有一个简单的 angular7 应用程序,它只有两条主要的“文章”路线。如果您在本地测试它,它会起作用,但是当您放在 github 页面上时,它只会加载页面的 css。我按照 documentation 的 Angular 文档进行了部署我还尝试使用 gh-pages 工具。但他们都没有工作。如果我删除我的路线,它将起作用。

这是我在控制台上遇到的错误。

1 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'blogfolio'
Error: Cannot match any routes. URL Segment: 'blogfolio'
at t.noMatchError (main.5443131190bc79920d7b.js:1)
at e.selector (main.5443131190bc79920d7b.js:1)
............

rodnorm.github.io/:1 Failed to load resource: the server responded with a status of 404 ()

这是我的代码:

应用程序.rounting.ts

import { MainComponent } from './main/main.component';
import { ArticleComponent } from './article/article.component';
import { Routes } from "@angular/router";

export const routes: Routes = [

{
path: '', component: MainComponent
},
{
path: 'article', component: ArticleComponent
}
];

这是在 articleList.component.html 里面

<div class="post-preview" [routerLink]="['/article']">

这是 app.routing.module

import { routes } from './app.routing';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';

@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }

如果你们想在这里查看整个代码,请访问 repo这是部署 link .

最佳答案

如果您的 Angular 应用程序中有路由器,那么它在 GitHub 页面中将不可用,您将获得一个 404 页面。

要解决这个问题,你需要告诉服务器当找不到页面时需要做什么,所以复制 index.html 文件并将其重命名为 404.html。这确保所有未找到的路由都将重新路由到 Angular 路由器,并且它会正确处理。

请引用this获取更多信息。谢谢!

关于angular - 将 Angular 7 部署到 github 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53621549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com