routing - AngularJs $locationProvider.html5Mode(true); for remove Hash to URL not work -
i have problem function $ locationprovider.html5mode (true), setting:
var app = angular.module("app", [ "ngroute", "nganimate" ]); // route config app.config(['$routeprovider','$locationprovider', function($routeprovider, $locationprovider){ $routeprovider. when("/archive", { templateurl: "archive.php", controller: "archivectrl", animate: "slide-left" }). when("/single", { templateurl: "single.php", controller: "singlectrl", animate: "slide-left" }). otherwise({ redirectto: "/archive" }); $locationprovider.html5mode(true); });
in head tag:
<head> <base href="/"> </head>
the root of site
site.com/main.php
where main.php contains div ng-view
any idea why not work?
here working example created on jsfiddle, removed templateurl , use template instead, shouldn't matter in case(you asking how html5mode , base work)
html
<div ng-controller="mainctrl"> <a href="/single">single</a> <a href="/archive">archive</a> <div ng-view></div> </div>
javascript
var app = angular.module("myapp", [ "ngroute" ]) .config(['$routeprovider', '$locationprovider', function($routeprovider, $locationprovider) { $routeprovider .when("/archive", { template: "<p>archive</p>" }) .when("/single", { template: "<p>single</p>" }) .otherwise({ redirectto: "/archive" }); $locationprovider.html5mode(true); }]) .controller("mainctrl", function mainctrl($scope, $location) { $scope.$location = $location; });
Comments
Post a Comment