gpt4 book ai didi

angularjs 1.6.0(现在最新)路线不起作用

转载 作者:行者123 更新时间:2023-12-02 07:57:34 25 4
gpt4 key购买 nike

我本来希望在 Stackoverflow 上看到这个问题,但没有。显然我是唯一一个遇到这个在我看来很常见的问题的人。

我正在做一个基本项目,但路线似乎不起作用,尽管我到目前为止所做的一切似乎都是正确的。

我的 index.html 文件中有这段 html:

<html>
<head ng-app="myApp">
<title>New project</title>
<script src="https://code.angularjs.org/1.6.0/angular.min.js"></script>
<script src="https://code.angularjs.org/1.6.0/angular-route.min.js"></script>

<script src="app.js"></script>
</head>
<body>
<a href="#/add-quote">Add Quote</a>
<div ng-view ></div>
</body>
</html>

这是我的 app.js:

var app = angular.module('myApp', ['ngRoute']);


app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/add-quote', {
templateUrl: 'views/add_quote.html',
controller: 'QuoteCtrl'
})
.otherwise({ redirectTo: '/' });
}]);

现在,当我访问该页面时,以下是我在网址中得到的内容:

http://localhost:8000/admin#!/

当我点击添加引用按钮时,我得到:

http://localhost:8000/admin#!/#%2Fadd-quote

这里可能有什么问题?感谢您的帮助

最佳答案

只需在 href 中使用 hashbang #! 即可:

 <a href="#!/add-quote">Add Quote</a>
<小时/>

由于aa077e8 ,用于 $location hash-bang URL 的默认哈希前缀已从空字符串 ('') 更改为 bang ('!')。

如果您确实不想使用哈希前缀,那么您可以通过向应用程序添加配置 block 来恢复以前的行为:

appModule.config(['$locationProvider', function($locationProvider) {
$locationProvider.hashPrefix('');
}]);

欲了解更多信息,请参阅

<小时/>

抱歉,我的态度太高了,但是……这个是怎么发布的?这是一个巨大的、破坏性的错误。 — @MiloTheGreat

The breaking change as by #14202 should be reverted as the reference specification was already officially deprecated #15715

I'm going to close this issue because we haven't got any feedback. Feel free to reopen this issue if you can provide new feedback.

https://github.com/angular/angular.js/issues/15715#issuecomment-281785369

关于angularjs 1.6.0(现在最新)路线不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41211875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com