Thursday, 9 October 2014

angularjs dynamic links and $locationProvider.html5Mode(true);

1,

 with $locationProvider.html5Mode(true);
 then you should make the links like this : href='/xxxx'
 and in the route.js you should have the templateurl like this: templateUrl: '/views/monday.html', the root slash is important.

2, 
 without $locationProvider.html5Mode(true);
 then you should make the links like this : href='#/xxxx'



Because with $locationProvider.html5Mode(true);

All redirect is based on the current url.
So, if the route.js is:
{
                        id: 'monday',
                        url: '/monday/:xx',
                        templateUrl: 'views/monday.html',
                        controller: 'MondayCtrl'
}
then the an accessing to 0.0.0.8000/moday/abc will be redirected to:
http://0.0.0.0:8000/monday/views/monday.html 

So in this case, all links should be in abstract form.

Note: window.location.href = "/monday/abc", this different. this code is used to change the url of your browser.


No comments:

Post a comment