基本href和角路由和意见 [英] Base Href and Angular Routing and Views

查看:152
本文介绍了基本href和角路由和意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个web应用程序,它定义了<基本href =凤凰/>在头文件作为解释的在这篇文章

I'm developing a web application which defines the <base href="phoenix/"> in the header as explained in this article.

所映射的默认URL是的http://本地主机/凤凰/ 然而在标题定义基本标记,即使我的看法和路线不被重定向正确

The default URL that is mapped is http://localhost/phoenix/ however even when defining the base tag in the header my views and routes are not being redirected correct.

启用HTML5我的路由:

I enabled HTML5 routing:

$locationProvider.html5Mode(true);

然后我定义路线如下:

and then defined my route like:

app.config(["$routeProvider", function ($routeProvider) {
    $routeProvider.when('/login', {
        templateUrl: '/views/login.html',
        controller: 'LoginCtrl'
    });
}]);

它试图解决它为:

It tries to resolve it as:

 GET http://localhost/views/login.html 404 (Not Found) 

它正常工作,如果我追加的基本URL到 /凤凰/登录路径。我应该追加了通过一个变量设置或东西还是我失去了一些东西,这应该工作。此外,这是要上工作说IE8与头属性基地?

It works correctly if I append the base url to the /phoenix/login paths. Should I have to append that via a variable I set or something or am I missing something and this should work. Also, is this going to work on say IE8 with the header attribute base?

推荐答案

从视图中删除斜杠

app.config(["$routeProvider", function ($routeProvider) {
    $routeProvider.when('/login', {
        templateUrl: 'views/login.html',
       controller: 'LoginCtrl'
    });
}]);

和制作环节,如:

 <a href="login">Login</a>

但在离开的斜线为路由解决了这个问题。

but leaving the slash for the route resolved the problem.

这篇关于基本href和角路由和意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆