问题描述
我不明白为什么我无法使它正常工作。
I don't understand why I can't get this to work.
我将分享相关代码,如果您需要查看更多内容,请告诉我
I'll share the relevant code, let me know if you need to see more stuff.
Index.html
<div class="col-md-3"><a href="#/liberals">Liberals</a></div>
app.js
var app = angular.module('myApp', ['ngRoute']);
app.config(function ($routeProvider) {
$routeProvider.
when("/liberals", {
templateUrl: "partials/liberals.html"
, controller: "LiberalsController"
});
});
app.controller('LiberalsController', function ($scope, $http) {
var url = "workingURL"; /// changed function to a simple string message to test
$scope.message = "Hello Liberals";
});
(部分视图)liberals.html
<h1>Hello</h1>
{{message}}
PS:我不是在政治仇恨网站上工作
PS: I'm not working on a political hate website for or against liberals!
推荐答案
从AngularJS 1.6开始, hashPrefix 已更改为
!
。
As of AngularJS 1.6, the default value of the
hashPrefix
has been changed to !
.
有两种方法可以使您的路由与AngularJS 1.6一起使用+:
There's two ways to get your routing to work with AngularJS 1.6+:
- 将哈希前缀(
!
)添加到您的href
:
Add the hashprefix (
!
) to yourhref
's:
< a href =#!/自由主义者> Liberals< / a>
- 更改(删除)
hashPrefix
使用$ locationProvider
的值:
Change (remove) the
hashPrefix
value using$locationProvider
:
$ locationProvider.hashPrefix('');
我创建了一个可工作的plunkr,在其中使用了第二种方法:
I've created a working plunkr in which I used the second approach:https://plnkr.co/edit/oTB6OMNNe8kF5Drl75Wn?p=preview
有关此重大更改的提交可以在此处
The commit regarding this breaking change can be found here
这篇关于带有ng-view的角度路由不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!