作为示例程序,我下载了this plunker从教程到测试不同页面中的选项卡路由。我下载了完整的 zip 并按原样运行(例如同一目录中的文件,链接是 CDN)但它不起作用。我认为 Angular 文件不包括在内,因为它显示了这个输出:
单击以下选项之一。
tab 1<br/>
tab 2
{{ path }} //supposed to model the variable
但它在 plunker 中运行良好。基本 href 路径或版本有问题吗?我尝试为 angular.min.js 添加我自己的文件而不是链接,但它仍然不起作用。
这是 html:
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>
document.write('<base href="' + document.location + '" />');
</script>
<link href="style.css" rel="stylesheet" />
<script data-semver="1.2.7" src="http://code.angularjs.org/1.2.7/angular.js" data-require="angular.js@1.2.x"></script>
<script src="http://code.angularjs.org/1.2.7/angular-route.js"></script>
<script src="app.js"></script>
</head>
<body ng-app="plunker">
<div ng-controller="NavCtrl">
<p>Click one of the following choices.</p>
<ul>
<li ng-class="{active: isActive('/tab1')}"><a href="#/tab1">tab 1</a>
</li>
<li ng-class="{active: isActive('/tab2')}"><a href="#/tab2">tab 2</a>
</li>
</ul>
<pre>{{ path }}</pre>
</div>
<div ng-view></div>
</body>
</html>
最佳答案
因为 document.location
返回给你一个 Object
,试试 document.location.origin
。
关于javascript - Angularjs 路由不适用于基本 href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24692012/