By default, AngularJS will route URLs with a hashtag.

For example:

  • http://example.com/
  • http://example.com/#/users
  • http://example.com/#/roles

It is very easy to get clean URLs and remove the hashtag from the URL.

There are 2 things that need to be done.

  1. Configuring $locationProvider
  2. Setting our base for relative links

app.users.routes.js

(function() {
'use strict'; angular
.module('app.users')
.config(['$routeProvider', ', $locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.
when('/users', {
templateUrl: '/app/components/users/views/user-list.tpl.html',
controller: 'UserController'
}); // Use the HTML5 History API
$locationProvider.html5Mode(true
);
}]); })();

What is the HTML5 History API? It is a standardized way to manipulate the browser history using a script. This lets Angular change the routing and URLs of our pages without refreshing the page. For more information on this, here is a good HTML5 History API Article. The $locationProvider will automatically fallback to the hashbang method for browsers that do not support the HTML5 History API.

To link around your application using relative links, you will need to set a <base> in the <head> of your document.

index.html

<!DOCTYPE html>
<html ng-app="app">
<head>
<title></title>
<meta charset="utf-8" />
<base href="/">
</head>
<body>
<ul>
<li>
<a href="#/users">Users</a>
</li>
<li>
<a href="#/roles">Roles</a>
</li>
</ul> <ng-view></ng-view> <script type="text/javascript" src="/assets/libs/angular/angular.min.js"></script>
<script type="text/javascript" src="/assets/libs/angular/angular-route.min.js"></script>
<script type="text/javascript" src="/app/app.js"></script>
<script type="text/javascript" src="/app/components/users/app.users.js"></script>
<script type="text/javascript" src="/app/components/users/app.users.routes.js"></script>
<script type="text/javascript" src="/app/components/users/controllers/user.controller.js"></script>
<script type="text/javascript" src="/app/components/roles/app.roles.js"></script>
<script type="text/javascript" src="/app/components/roles/app.roles.routes.js"></script>
<script type="text/javascript" src="/app/components/roles/controllers/role.controller.js"></script>
</body>
</html>

最新文章

  1. 修改Centos 6.5的yum源
  2. mySql的学习心得
  3. 一台机器运行多个JBoss 4.2.3多实例,或多个同一版
  4. 统计《ASP.Net特供视频教程》总长度
  5. [转]iptables详解
  6. HDU 5212 Code
  7. eclipse JAVA 类元素 快速添加set和get方法
  8. 有关mipmaps
  9. CodeIgniter 引入自定义公共函数
  10. SQL Server 2008 R2 找不到 Install SQL Server Profiler 找不到 事件探查器 解决
  11. WCf的理解
  12. 如何运用同余定理求余数【hdoj 1212 Big Number【大数求余数】】
  13. Qt实现不同Treewidget之间拖拽
  14. 开源 java CMS - FreeCMS2.3员
  15. MongoVUE的table view视图不显示列标题
  16. C# Select
  17. TerraGate软件安装后,不能启动的解决办法
  18. mpVue小程序全栈开发
  19. setfacl 设置文件访问控制列表
  20. 字符串CRC校验

热门文章

  1. 【BZOJ】1987: Zju2672 Fibonacci Subsequence
  2. Java_Java Compiler 应用实例
  3. ubuntu 12.04 安装wireshark
  4. C#.NET Form设置/取消开机自动运行,判断程序是否已经设置成开机自动启动(转载)
  5. servlet session 相关
  6. Android自定义UI模板
  7. html5 语义
  8. CSS3初学篇章_5(背景样式/列表样式/过渡动画)
  9. dede数据库类使用方法 $dsql
  10. 对C++下struct 和 类默认继承的认识