Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I know one possible way to remove '#' from AngularJs route url is to enable html5 mode. like:

$locationProvider.html5Mode(true) if window.history && window.history.pushState

This is work, but the problem is after I click menu and switch to the correct page and refresh it, it shows template is missing!! I pretty sure this is because after refresh page, the view will automatically load rails view with the url instead of AngularJs route url. Could someone help me?

share|improve this question
    
Check that you've set the base href (i.e. <base href=".">) appropriately on your main index page. The official documentation on Using $location provides further information on this. –  miqid Jul 14 '14 at 8:57
    
@miqid I know I should do add base href. From other posts, everyone said it needs <base href="/"> rather than a '.'. But it is worthy to have a try. And the url become myworld.dev/#%2Fmy_favorites%2Fnovels that means it not works. And <base href="/"> didn't work either. –  Perpherior Jul 15 '14 at 0:57
    
Sure, the "." was just a suggestion, prefer / if ends up working for you. It's strange how routing is causing your URL to have encoded values though (i.e. the %2F, which should be forward slashes). –  miqid Jul 15 '14 at 1:03
    
@miqid The point is even if I add <base href='/'> and enable html5Mode, it still displays with an error -- missing template. I can only use nav bar to redirect page. Once refresh it, the error occurs again. –  Perpherior Jul 16 '14 at 5:21

1 Answer 1

up vote 2 down vote accepted

From the angular docs

Server side
Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html)

The reason for this is that when you first visit the page (/about), e.g. after a refresh, the browser has no way of knowing that this isn't a real url, so it goes ahead and loads it. However if you have loaded up the root page first, and all the javascript code, then when you navigate to /about angular can get in there before the browser tries to hit the server and handle it accordingly

Thanks to AngularJS HTML5 mode reloading the page gives wrong GET request

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.