0

My question is similar to this one, but my goal is to make the hashbang URLs silently redirect to the html5Mode style. I mean, when

example.com/#!/hello 

gets entered, it should be silently changed to

example.com/hello 

in order for existing links to stay valid. Compatibility with old browsers doesn't matter (as AFAIK everything supported by angularjs 1.3 works with the html5Mode).

Maybe I'm just misunderstanding the answer, but I can't see it there. I've got the html5Mode working without problems, but I sort of want two in one.

2
  • url fragments are not sent to the server by the browser. there's NO way for mod_rewrite to change that url, because the #!/hello portion would never get sent to the server in the first place. Commented May 27, 2015 at 16:59
  • @MarcB Sure, but I wanted angularjs to do it, not the server. More exactly 1. both URLs should work the same. 2. instead of the former, the latter should be displayed. The server returns the right content already (it sort of ignores the pathInfo). Commented May 27, 2015 at 17:16

2 Answers 2

1

That's how it's working in mine and I'm not doing anything special? If I type mysite.com/angularapp/#/accounts/29 using Chrome, it gets replaced with mysite.com/angularapp/accounts/29

My routing config contains:

 function($locationProvider) { $locationProvider.html5Mode(true).hashPrefix(""); } 

I'm on Angular 1.2.21, I'm not sure if that behavior would have changed on 1.3.x.

Sign up to request clarification or add additional context in comments.

1 Comment

The "special" thing you're doing is specifying both the html5Mode and the prefix. I missed the second.
0

You can do it manually in JS with something liek this:

window.location.replace( window.location.href.replace(new RegExp("^([^?]+/)#!/(.*)$"), function (all, s1, s2) { return s1 + s2; } ) ); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.