John Smith John Smith - 2 months ago 20
AngularJS Question

Removing # my angularjs pages do not work

I learn angularjs after a tutorial and I saw that you can remove # from the link. I did that but then my partials(from templateUrl) did't come in the page anymore.
Can someone please tell me where I'm wrong?

angular.module('myApp', ['ngRoute'])
.controller('mainController', ['$scope', '$location', '$log', function($scope, $location, $log) {


.controller('secondController', ['$scope', '$location', '$log', function($scope, $location, $log) {


.config(function($routeProvider, $locationProvider) {
// $routeProvider lets us specify routes
.when('/', {
templateUrl: 'pages/main.html',
controller: 'mainController'
.when('/second', {
templateUrl: 'pages/second.html',
controller: 'secondController'

<!DOCTYPE html>
<html lang="en-us" ng-app="myApp">
<title>Learn and Understand AngularJS</title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta charset="UTF-8">
<base href="/">
<!-- load bootstrap and fontawesome via CDN -->
<link rel="stylesheet" href="//" />
html, body, input, select, textarea
font-size: 1.05em;

<!-- load angular via CDN -->
<script src="//"></script>
<script src="//"></script>
<script src="angularjs-learn-understand/ch05/app.js"></script>

<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="/">AngularJS</a>

<ul class="nav navbar-nav navbar-right">
<li><a href="#"><i class="fa fa-home"></i> Home</a></li>
<li><a href="#/second"><i></i> Second</a></li>

<div class="container">

<div ng-view></div>




<h1>This is Main.</h1>


<h1>This is second.</h1>

So in my browser I don't get main.html and second.html when I click on Home and Second. Why?


The UI Router github docs mentions:

When you have html5Mode enabled, the # character will no longer be used in your urls. The # symbol is useful because it requires no server side configuration. Without #, the url looks much nicer, but it also requires server side rewrites.

When you are trying to access your app in html5Mode (routes without any hash) then first of all you would need to remove the "#" from each one of your links (in this case the links are: Home, Second).


  • "#" would just be "/"
  • "#/second" would be "/second"

After this, you would also need to enable server side URL Rewrites. Please checkout this link and configure your server as per the server that you are using.