Part 27 Remove # from URL AngularJS
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Part 27 Remove # from URL AngularJS,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1937字,纯文字阅读大概需要3分钟。
内容图文
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 ="/" />
原文:http://www.cnblogs.com/gester/p/5494394.html
内容总结
以上是互联网集市为您收集整理的Part 27 Remove # from URL AngularJS全部内容,希望文章能够帮你解决Part 27 Remove # from URL AngularJS所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。