Angular.js route

编程入门 行业动态 更新时间:2024-10-26 04:20:20
Angular.js route - 如何从路由中删除html文件名(Angular.js route — how to remove html filename from the route)

好的,所以我是一个Angular.js新手,我正在努力创建一些基本的路由。 我的路由有以下定义:

JBenchApp.config(['$routeProvider', function($routeProvider) { $routeProvider. when('/dashboard', { templateUrl: 'partials/dashboard.html', controller: 'JBenchCtrl' }). when('/calendar', { templateUrl: 'partials/calendar.html', controller: 'JBenchCtrl' }). otherwise({ redirectTo: '/dashboard' }); }]);

当我加载页面http:// localhost:53465 / default.html我得到的是

http://localhost:53465/default.html#/dashboard

我怎样才能将其显示为

http://localhost:53465/dashboard

OK, so I am an Angular.js newbie and I am working on creating some rudimentary routing. I have the following definition for my routing:

JBenchApp.config(['$routeProvider', function($routeProvider) { $routeProvider. when('/dashboard', { templateUrl: 'partials/dashboard.html', controller: 'JBenchCtrl' }). when('/calendar', { templateUrl: 'partials/calendar.html', controller: 'JBenchCtrl' }). otherwise({ redirectTo: '/dashboard' }); }]);

When I load the page http://localhost:53465/default.html what I get is

http://localhost:53465/default.html#/dashboard

How can I make this show up as

http://localhost:53465/dashboard

最满意答案

您定义的路由是在URL中的hashbang之后出现的文本 - hashbang,因为您似乎没有将HTML5模式设置为true。

因此,当您加载页面http://localhost:53465/default.html ,AngularJS将尝试加载路由http://localhost:53465/default.html/#!/其中路由为/ - 文本在hashbang(#!)之后出现。

看看你的路线。 /没有路由处理程序。 因此,执行otherwise()函数,它只是重定向到路径/dashboard 。 因此,最终的URL是http://localhost:53465/default.html/#!/dashboard

如果要将URL加载为http://localhost:53465/dashboard则只需提供上述URL即可。 您不必指定default.html,因为路由处理程序负责加载相关的HTML文件(基于路由处理程序对象的templateUrl属性)

The routes that you have defined are the text that appear after the hashbang in the URL - hashbang because you do not seemed to have set HTML5 mode to true.

Thus, when you load the page http://localhost:53465/default.html, AngularJS will attempt to load the route http://localhost:53465/default.html/#!/ where the route is / - the text that appears after the hashbang(#!).

Look at your routes. There is no route handler for /. Thus, the otherwise() function is executed which simply redirects to the route /dashboard. Thus, the final URL is http://localhost:53465/default.html/#!/dashboard

If you want to load the URL as http://localhost:53465/dashboard then simply provide the above URL as it is. You don't have to specify default.html as the route handler takes care of loading the relevant HTML file (based on the templateUrl property of the route handler object)

更多推荐

本文发布于:2023-08-04 06:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1413168.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Angular   js   route

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!