javascript - Is there any way to avoid changing URL address bar when using ngview -


in this example ng-view directive doesn´t change url in address bar. when port example application address in bar changes url in 'href' link tag on every click, if put relative url (like example).

my html code

<div ng-view></div>  <div class="navheader">     <ul id="navitems" ng-controller="departments">         <li ng-repeat="department in departments">             <a href="{{department.url}}">                 {{department.name}}             </a>         </li>     </ul> </div> 

the href attribute has been built in code below:

http.get(service_root + '/depts').success(function (data) {   angular.foreach(data, function (value) {     value.url = service_root + '/dept/' + value.id; // line   });    model.departments = data; }); 

the answer no. point of ng-view update template based on current url location. it's spa equivalent of changing pages.

if want similar example you've linked, should using ng-switch.

edit updated due comment:

i question because everytime refresh on page, displays json returned service. happens because address bar filled in url restful service instead of keep page url.

the reason happens because using html pushstate history api (have google!) aka html5mode. means intents , purposes, you're telling browser you've loaded different page, despite being not changing page @ all. when hit refresh, browser requests url that's in address bar, server responds to, in case json.

one quick fix turn html5mode off in app's .config function:

$locationprovider.html5mode(false); 

this reverts using hash sytax, e.g. "path.to.your.site/#/about". doesn't nice, should job. angular prefix relative links prefix define.

the better option modify server, rest api under prefix, e.g. /api/, requests not /api/*, return index.html page. angular handles routing after that. means have best of both worlds - addresses nicer, (they don't have #), refresh etc. works expected.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -