AngularJS 路由问题不好 url
AngularJS routing issue bad url
已在我的应用程序中生成我的路线:
app.config( function($routeProvider){
$routeProvider
.when('/',{
templateUrl: './partials/home/home.html',
controller: 'mainCtrl'}
)
.when('/article',{
templateUrl: './partials/article/article.html',
controller: 'articleCtrl'}
)
.otherwise({
redirectTo: '/'
});
});
有效!
但是 link 很糟糕 :(
我这样创建 link :
<div class="read-more"><a href="#article">Lire plus...</a></div>
我的错link:
http://localhost:10001/#!/#article
vs 好的 link 是:
http://localhost:10001/#!/article
谁错了?
感谢
PS 我使用 node lite-server
这个http://localhost:10001/#!/article是对的url。
原因是,如果浏览器是 HTML5,浏览器 AngularJS 会将其重定向到 #!
否则只有#
.
在 $location
上阅读这篇 documentation here 以了解更多关于为什么会发生这种情况。
- Opening a regular URL in a legacy browser -> redirects to a hashbang URL
- Opening hashbang URL in a modern browser -> rewrites to a regular URL
已在我的应用程序中生成我的路线:
app.config( function($routeProvider){
$routeProvider
.when('/',{
templateUrl: './partials/home/home.html',
controller: 'mainCtrl'}
)
.when('/article',{
templateUrl: './partials/article/article.html',
controller: 'articleCtrl'}
)
.otherwise({
redirectTo: '/'
});
});
有效!
但是 link 很糟糕 :( 我这样创建 link :
<div class="read-more"><a href="#article">Lire plus...</a></div>
我的错link: http://localhost:10001/#!/#article
vs 好的 link 是: http://localhost:10001/#!/article
谁错了?
感谢
PS 我使用 node lite-server
这个http://localhost:10001/#!/article是对的url。
原因是,如果浏览器是 HTML5,浏览器 AngularJS 会将其重定向到 #!
否则只有#
.
在 $location
上阅读这篇 documentation here 以了解更多关于为什么会发生这种情况。
- Opening a regular URL in a legacy browser -> redirects to a hashbang URL
- Opening hashbang URL in a modern browser -> rewrites to a regular URL