0

my main directory folder name is angularjs and there have many files, file lists are given billow.

1.index.html
2.main.html
3.blue.html
4.red.html
5.green.html

i want to create routing using AngularJs, i have do that but facing error what i have wrong.

var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
  $routeProvider
    .when("/", {
      templateUrl: "index.html"
    })
    .when("/red", {
      templateUrl: "red.html"
    })
    .when("/green", {
      templateUrl: "green.html"
    })
    .when("/blue", {
      templateUrl: "blue.html"
    });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular-route.min.js"></script>

<body ng-app="myApp">

  <p><a href="#/">Main</a></p>

  <a href="#/red">Red</a>
  <a href="#/green">Green</a>
  <a href="#/blue">Blue</a>
  <div ng-view></div>
</body>

and i want to remove # simble from routing path

1 Answers1

0

Try replacing your code with below.

<p><a href="#!">Main</a></p>

<a href="#!red">Red</a>
<a href="#!green">Green</a>
<a href="#!blue">Blue</a>

<div ng-view></div>

If you want to remove the exclamation mark, you should add a config to the $locationProvider as below.

.config(function ($routeProvider,$locationProvider) {
    $locationProvider.hashPrefix('');
    $routeProvider

Refer, Exclamation mark after hash (#!) in angularjs app

Vishmi Money
  • 144
  • 1
  • 5