0

I have a singlepage application build with Angular 9 and I would like to use urls withoug a hashtag to navigate.

I enabled pushState / HTML5 mode by defining useHash

RouterModule.forRoot(routes,{useHash: false})

and in the index.html the "base entry:

<head>
    <base href="/" />

so far everything looks ok, but i see, that when requesting a site directly: instead of:

http://localhost:4200/#/upload?transactionId=100603804

using

http://localhost:4200/upload?transactionId=100603804

the whole angular application is reloaded again from the server. How could it be arranged, that i can use the links without '#' and also to avoid the reloading?

best regards

shane

4
  • When doing that, some configuration is necessary on your server because you are requesting a resource that does not really exist (/upload). A rewrite rule must be written so that the server will understand that it should actually serve index.html Commented Feb 10, 2021 at 17:13
  • The following answer is about angularJs but the logic is the same : stackoverflow.com/questions/15284038/… Commented Feb 10, 2021 at 17:14
  • I thought that modern browsers do not reload the whole application. Isn't it that he HashLocationStrategy is only needed to support older browsers? Commented Feb 10, 2021 at 17:34
  • What do you mean by the whole angular application is reloaded again from the server ? If you type that in the url and press enter, of course it will reload the whole application. But if place a button that triggers router.navigate(), it will just navigate without whole reloading Commented Feb 10, 2021 at 17:58

0

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.