angular - Angular:使用“GitHub”页面重新加载后获取“404”
问题描述
我已经Angular
在页面上部署了我的网站GitHub
,但我遇到了问题。
以下是我的route
设置:
const routes: Routes = [
{ path: '', redirectTo: 'main', pathMatch: 'full' },
{ path: 'main', component: AppMainComponent }
];
以下是我的部署命令:
- name: Build
run: |
npm install -g @angular/cli
npm install
ng build --prod --base-href=https://[user-name].github.io/[project-name]/
- name: Deploy
uses: JamesIves/github-pages-deploy-action@releases/v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_BRANCH: master
BRANCH: gh-pages
FOLDER: dist/[project-name]
如果我转到我的GitHub
页面“https://[user-name].github.io/[project-name]/”,它工作正常并重定向到“https://[user-name].github.io /[项目名称]/main" 成功。但是在我点击浏览器的重新加载按钮后,它显示404 page not found
给我。
我的 Angular 版本是 9.1.8。
谢谢!
解决方案
根据 Angular文档,您必须复制index.html
并命名它404.html
。
- 构建完成后,复制 docs/index.html 并将其命名为 docs/404.html。
bash ng build --prod --output-path docs --base-href/<project_name>/
推荐阅读
- google-visualization - magnifyingGlass 如何为 Geo Chart 工作?
- azure - 如何使用 Spring Cloud Security 通过 Azure AD 进行单点登录
- mysql - 将一个表中的多个值减去另一个表中的另一个值
- c# - 对每个 textChanged 事件重复相同的步骤
- react-native - 反应本机导航参数不适用于 Switch navigator
- php - Wordpress:在获取模板时,部分未显示
- regex - 如何通过正则表达式删除所有之间的内部文本?
- ms-access - 定期自动执行 Access 模块的无人值守运行
- r - lubridate 从函数内的句点中提取对象
- ruby-on-rails - 我正在尝试将潜在客户发送到外部 API,但 CORS 策略阻止了我。有什么见解吗?