Angularjs Normal Links with html5Mode

前端 未结 4 1055
忘了有多久
忘了有多久 2020-11-28 03:46

I am working with angularjs in html 5 mode. Which appears to take control of all href\'s on the page. But what if I want to have a link to something within the same domain o

4条回答
  •  遥遥无期
    2020-11-28 04:18

    Other solution. All links will work normally (reload page). Links marked by ng-href="/path" will play on pushState. Small JS hack help with it.

    .config(["$locationProvider", function($locationProvider) {
        // hack for html5Mode customization
        $('a').each(function(){
            $a = $(this);
            if ($a.is('[target]') || $a.is('[ng-href]')){
            } else {
                $a.attr('target', '_self');
            }
        });
    
        $locationProvider.html5Mode(true);
    }])
    

提交回复
热议问题