在我的应用程序中生成我的路线:
app.config( function($routeProvider){
$routeProvider
.when('/',{
templateUrl: './partials/home/home.html',
controller: 'mainCtrl'}
)
.when('/article',{
templateUrl: './partials/article/article.html',
controller: 'articleCtrl'}
)
.otherwise({
redirectTo: '/'
});
});
成功了!
但是链接是 bas :( 我这样创建我的链接:
<div class="read-more"><a href="#article">Lire plus...</a></div>
我的错误链接: http://localhost:10001/#!/#article
与好的链接是: http://localhost:10001/#!/article
谁错了?
谢谢
PS 我用的是 node lite-server
最佳答案
这http://localhost:10001/#!/article是正确的网址。
原因是,如果浏览器是 HTML5 浏览器,AngularJS 会将其重定向到 #!
否则只会是#
。
阅读此 documentation here在 $location
上找到更多关于为什么会发生这种情况的信息。
- 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
关于javascript - AngularJS 路由问题错误的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41859858/