0

I'm working on an Angular2 web application that initially used HashLocationStrategy. HashLocationStrategy adds a # to the URL like so: https://example.com/#/some-page. A change has been made, and I'm no longer using HashLocationStrategy, so the URL now looks like: https://example.com/some-page. This all works fine. However, I want to add a 301 redirect on my NGINX server to specify this change in location. Should I use rewrite regex for this? If so, what would the pattern be to redirect from # to no #. Thanks!

awebdev
  • 997
  • 2
  • 10
  • 27
  • 1
    The fragment (content after `#`) doesn't actually get sent to the server, so that doesn't make much sense. That's *why* it's often used for simple SPA routing. See e.g. https://stackoverflow.com/q/14462218/3001761. – jonrsharpe Mar 20 '19 at 17:05
  • But my new routing won't be using #, so it will be sent to the server. Are you saying that since the previous # routes weren't being sent to the server, that I don't need to provide a 301 redirect for the new non # routes? Thanks :) – awebdev Mar 20 '19 at 17:52
  • 1
    You *can't*, the users will end up on the home page `/` when they try to visit e.g. `/#/some-page`, and the server won't have the information about where they actually wanted to go for a redirect. They'll have to update their bookmarks themselves. – jonrsharpe Mar 20 '19 at 17:53
  • Ahhh I see. I have implemented some logic in my Angular code to redirect # to non hash already, so /#/some-page will go to /some-page. I was just thinking that a 301 on the server would be necessary as well. Thanks for the info – awebdev Mar 20 '19 at 17:56

0 Answers0