好的,所以我是一个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/dashboardOK, 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#/dashboardHow 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)
更多推荐
发布评论