javascript - #%2F is getting added in Angular routing and not working in angular 1.6.4 -
i trying set routes in first single page application 2 days,i dont know happening application.when click of link,like clicked login link http://localhost:3000/#!/#%2flogin gets in requested url , when did experiments see found http://localhost:3000/#!/login shows me login template. how correct it. code html>>
<a href="/#/">posts</a> <a class="nav-item nav-link" href="/#/register">register</a> <a class="nav-item nav-link" href="/#/login">login</a>
route.js>>
angular.module('app') .config(function ($routeprovider) { $routeprovider .when('/',{controller:'postsctrl',templateurl:'posts.html'}) .when('/register',{controller:'registerctrl',templateurl:'register.html'}) .when('/login',{controller:'loginctrl',templateurl:'login.html'}) });
first off, can remove hash entirely enabling html5 mode. add configuration:
$locationprovider.html5mode({ enabled: true, requirebase: false });
this post might help: how remove hash # angularjs ng-route
secondly, don't need reference hash when linking template. use simple go function redirect pages in angular app. call template want load calling go('./template_name'). also, should use ng-click instead of href.
vm.go = function(_path) { $location.path(_path); }
Comments
Post a Comment