Search code examples
angulargithub-pages

Issues hosting angular application in Github Pages


I am attempting to host an angular app in github pages. I have gotten the site setup so the main page displays…but my main page requires an authorization redirect that forces my site to go the dashboard component. So I end up with a url like this: https://www.example.com/dashboard/#accessToken=someToken&bearer=someBearer

The problem is that on the redirect back to the dashboard component I get a “404 file not found”. It appears that this happens on any page I attempt to go to that is not the home page. I have been looking everywhere trying to find a solution to this but I can’t.

I have read about tracking the last visited page in session storage in order to redirect there through the index page but I was not able to get that to work. I have also attempted changing the base url set in the index page but that doesn't seem to change anything either.


Solution

  • The default location strategy is PathLocationStrategy in Angular projects.

    There are 3 strategies in Angular (PathLocationStrategy and HashLocationStrategy, MockLocationStrategy) and you can know more details on this link.

    If you are using PathLocationStrategy, pls change it to HashLocationStrategy and try again. This will solve your problem.