2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GitLab PagesでTOP画面以外もURL直打ちで画面遷移できるようにする

Posted at

GitLab PagesにAngularプロジェクトをデプロイする場合、単純にpublicにビルドファイルをコピーするだけだと、URL直打ちした場合やF5でリロードした際にTOP画面以外は404エラーになります。

それを解決する方法をメモしておきます。

解決策

index.htmlをコピーして404.htmlを作成します。
こうすることで、TOP画面以外の場合に404.htmlにアクセスされます。
中身はindex.htmlのため、正常にルーティングされるというわけですね。

.gitlab-ci.yml
image: node:latest

pages:
  stage: deploy
  script:
  - npm install -g @angular/cli@latest
  - npm install
  - ng build --prod --aot
  - mkdir public
  - mv dist/project/* public/
  # index.htmlをコピーして404.htmlを生成する
  - cp public/index.html public/404.html
  artifacts:
    paths:
    - public
  only:
  - master

GitLab Issue

ここに書いてありました。
https://gitlab.com/gitlab-org/gitlab-pages/issues/23#note_57499396

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?