Part 27 Remove # from URL AngularJS

There are 4 simple steps to remove # from URLs in Angular.

Step 1 : Enable html5mode routing. To do this inject $locationProvider into config() function in script.js and call html5Mode() method passing true as the argument value. With this change the config function will now look as shown below.

.config(function ($routeProvider, $locationProvider) {
    $routeProvider
        .when("/home", {
            templateUrl: "Templates/home.html",
            controller: "homeController"
        })
        .when("/courses", {
            templateUrl: "Templates/courses.html",
            controller: "coursesController"
        })
        .when("/students", {
            templateUrl: "Templates/students.html",
            controller: "studentsController"
        })
    $locationProvider.html5Mode(true);
})

Step 2 : In index.html, remove # symbols from all the links. The links in index.html should look as shown below.

<a href="home">Home</a>
<a href="courses">Courses</a>
<a href="students">Students</a>

Step 3 : Include the following URL rewrite rule in web.config. This rewrite rule, rewrites all urls to index.html, except if the request is for a file, or a directory or a Web API request.

<system.webServer>
  <rewrite>
    <rules>
      <rule name="RewriteRules" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAll">
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
        </conditions>
        <action type="Rewrite" url="/index.html" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

Step 4 : Set the base href to the location of your single page application. In the head section of index.html include the following line.

<base href="/" />
时间: 2024-10-07 01:12:49

Part 27 Remove # from URL AngularJS的相关文章

27. Remove Element【easy】

27. Remove Element[easy] Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. The order of elements can be ch

LeetCode 27.Remove Element 数组元素删除

27. Remove Element Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. The order of elements can be changed.

[Leetcode][Python]27: Remove Element

# -*- coding: utf8 -*-'''__author__ = '[email protected]' 27: Remove Elementhttps://oj.leetcode.com/problems/remove-element/ Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can b

No.27 Remove Element

No.27 Remove Element Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length. Tags: Array Two Pointers 移除数组中所有的给定数

27. Remove Element(js)

27. Remove Element Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memor

27. Remove Element

Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length. AC代码: class Solution(object): def removeElement(self, num

leetcode 27 Remove Element

Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length. 题解:水题.遇到val就和最后一个不是val的数交换位置就好了. class Solution { public:

LeetCode记录之27——Remove Element

这道题跟26题很类似,并且有官方的答案.看了官方的答案之后发现写得特别巧,自己做的题太少思路太窄.有意思的是我的算法的时间复杂度是O(N^2),官方的是O(N),我的实际运行时间还少了2ms. iven an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must

27. Remove Element java solutions

Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. The order of elements can be changed. It doesn't matter