3

I have deployed my Angular website on GitHub page, but I got a problem.

The below is my route setting:

const routes: Routes = [
  { path: '', redirectTo: 'main', pathMatch: 'full' },
  { path: 'main', component: AppMainComponent }
];

The below is my deployment commands:

- 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]

If I go to my GitHub page, "https://[user-name].github.io/[project-name]/", it worked fine and redirected to "https://[user-name].github.io/[project-name]/main" successfully. But after I clicked reload button of the browser, it showed 404 page not found to me.

My Angular version is 9.1.8.

Thanks!

1 Answer 1

11

According to the Angular doc, you have to make a copy of index.html and name it 404.html.

  1. When the build is complete, make a copy of docs/index.html and name it docs/404.html.

bash ng build --prod --output-path docs --base-href/<project_name>/

Sign up to request clarification or add additional context in comments.

1 Comment

correct ng build --prod --output-path docs --base-href project_name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.