Reputation: 1770
I am new in angularJs. I just tried to route pages in angularJs. It's working but '#' symbol is shown. So I have used
$locationProvider and $locationProvider.html5Mode(true);
but it's not working. So I am giving my code bellow to seek for a help to find the problem. I am using CDN of angularJs.
The project Structure is:
app.Js File is
'use strict';
angular.module('myApp', ['myApp.controllers', 'ngRoute']);
angular.module('myApp').config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/view1', {
controller: 'Controller1',
templateUrl: 'partials/view1.html'
})
.when('/view2', {
controller: 'Controller2',
templateUrl: 'partials/view2.html'
});
$locationProvider.html5Mode(true); //activate HTML5 Mode
});
Controller is:
'use strict';
angular.module('myApp.controllers', [])
.controller('Controller1', function ($scope) {
$scope.message = "Hello, world";
})
.controller('Controller2', function ($scope) {
$scope.now = new Date();
});
Html Page is:
<!doctype html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="utf-8">
<title>AngularJS Routing</title>
<link rel="stylesheet" href="app.css"/>
<base href="/">
</head>
<body>
<ul class="menu">
<li><a href="/view1">view1</a></li>
<li><a href="/view2">view2</a></li>
</ul>
<ng-view></ng-view>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-route.js"></script>
<script src="app.js"></script>
<script src="controllers.js"></script>
</body>
</html>
Upvotes: 2
Views: 2115
Reputation: 3385
Your base should be your project folder path. In your case
<base href="/untitled1/">
Also I hope you are handling the page refresh redirection through .htaccess
Refer this link for more info in this
Upvotes: 2