AngularJS application links/routes in anchor tag with HTML5 mode -
how link other angularjs application locations within anchor a tag? using html5 hashless mode , avoid having page reload.
for example, in non-html5 mode this:
<a href='#/path'>link</a> in html5 mode can this:
<a href='/path'>link</a> but causes browser reload new url. i've tried using ng-href , /#/path syntax none of them seem work i'd like.
how link anchor tag?
update:
it seems possible without using $location, have keep same base link. from docs:
when use html5 history api mode, need different links in different browsers, have specify regular url links, such as: <a href="/some?foo=bar">link</a>
when user clicks on link,
- in legacy browser, url changes /index.html#!/some?foo=bar
- in modern browser, url changes /some?foo=bar
in cases following, links not rewritten; instead, browser perform full page reload original link.
- links contain target element. example: <a href="/ext/link?a=b" target="_self">link</a>
- absolute links go different domain. example: <a href="http://angularjs.org/"></a>
- links starting '/' lead different base path when base defined. example: <a href="/not-my-base/link">link</a>
old:
you should use $location service. inject controller , put on $scope (or in convenience method):
function mainctrl($scope,$location){ $scope.goto = function(path){ $location.path(path); } } <a ng-click="goto('/path')">link</a>
Comments
Post a Comment