1

I'm porting my website from an Angular client side site to React with server side rendering. I'm using the React starter kit with the universal-router.

My customers have old links that use the hashbang form. How can I support these old links in my new app?

e.g I want to redirect all mydomain.com/#/path/to/page to mydomain.com/path/to/page

Eldad
  • 1,067
  • 16
  • 36
  • 2
    The server never sees the hashbang routes. I do not think you can support these old links with only server-side rendering. You will have to run some code similar to Yura's answer on the client. – Brandon Jan 11 '17 at 15:30
  • I ended up adding some code to the client side, see my comments to Yura's answer. – Eldad Jan 12 '17 at 11:21

1 Answers1

1
if(location.hash.indexOf('#')===0) {
    location.href = location.hash.replace('#','') 
}
Yura
  • 2,690
  • 26
  • 32
  • 1
    Thanks, I took your answer and modified it to my needs: if(location.hash.indexOf('#')===0) { location.pathname = location.hash.replace('#','') location.hash = "" history.replace(location); } – Eldad Jan 12 '17 at 11:19