question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Router LocationStrategy not a "local URL", baseHref results in 404

See original GitHub issue

Description

Doc is misleading ‘[LocationStrategy and browser URL styles ]’(https://angular.io/guide/router#locationstrategy-and-browser-url-styles) says:

“this is a strictly local URL the browser won’t send this URL to the server and will not reload the page” and “a technique that changes a browser’s location and history without triggering a server page request”

🔬 Minimal Reproduction

https://mysite.com/basehref/app/route/featuremoduleroute shows 404

The angular browser navigation does trigger server a page request.

What’s the affected URL?**

private, can supply on request

Reproduction Steps**

I have a azure static website and am hosting the angular app in a sub-folder called /cp/ To build the angular app:

ng build --prod --output-path dist/cp/ --base-href /cp/

which is fine for viewing the root url, but as soon as I navigate to feature module child route, the server redirects my page to 404 as that URL route does not exist.

I have had to resort to ‘useHash:true’ on the router extraOptions.

Expected vs Actual Behavior**

Docs should say: Some applications will be on shared infrastructure and end up being hosted in a sub-folder. A hosted server’s routing re-write rules should redirect all traffic to your application, e.g. /baseHref/* to /baseHref/ If you do not have access to the server routing definition, even on modern browsers, use a baseHref during build and set ‘useHash:true’ on the app router extraOptions as detailed in the HashLocationStrategy docs.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
atscottcommented, May 2, 2021

@OzBob - Again, the statement you’re pointing to is referring to navigations through the Angular router. Deep links go to the server because there’s no page loaded. My opinion is that it’s not misleading at all but could potentially use clarification.

0reactions
angular-automatic-lock-bot[bot]commented, Jun 24, 2021

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

refreshing the page results in 404 error- Angular 6
For example: My URL is: http://localhost:4200/ , there are navigation links on the page, Fetch is one among them, when I clicks on...
Read more >
Route throws 404 error when refreshed · Issue #8788 - GitHub
It is working for manual URL change but not working with the URL refresh. Please suggest. And also comment on the best routing...
Read more >
Remove hash(#) at URL Angular and Still be able to refresh ...
And the results is my movie detail component can be refreshed and not getting 404 Not Found anymore but the url looks ugly...
Read more >
Common Routing Tasks - Angular
This topic describes how to implement many of the common tasks associated with adding the Angular router to your application.
Read more >
angular js app 404 not found on kubernetes - You.com
You.com is an ad-free, private search engine that you control. Customize search results with 150 apps alongside web results. Access a zero-trace private ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found