角路由ngRoute无法提取我的其他HTML文件 [英] Angular Routing ngRoute fails to pull my other HTML files
问题描述
因此,在四处浏览MEAN之后,我决定制作我的第一个MEAN应用程序,该应用程序非常小,除了路由使我的应用程序成为一页应用程序之外,其他所有功能似乎都可以使用.任何帮助将不胜感激!
So after reading here and there on MEAN, I decided to make my first MEAN application which is pretty small, all seems to work except the routeing to make my app a one-page app. Any help would be much appreciated!
app.config(function($routeProvider){
$routeProvider
.when('/', {
templateUrl: 'main.html',
controller: 'mainController'
})
.when('/login', {
templateUrl: 'login.html',
controller: 'authController'
})
.when('/register', {
templateUrl: 'register.html',
controller: 'authController'
});
});
无论如何,我采用了样板导航栏
Anyway, I adopted a boilerplate navigation bar
<nav class="navbar-fluid navbar-default navbar-fixed-top">
<div class="container">
<a class="navbar-brand" href="#">IoT</a>
<p class="navbar-text">IoT</p>
<p class="navbar-right navbar-text" ng-hide="authenticated"><a href="#/login">Login</a> or <a href="#/register">Register</a></p>
<p class="navbar-right navbar-text" ng-show="authenticated"><a href="#" ng-click="signout()">Logout</a></p>
<p class="navbar-right navbar-text" ng-show="authenticated">Signed in as {{current_user}}</p>
</div>
</nav>
而且,当我在localhost:3000上运行它时,我得到的首页地址是
And, when I run it on localhost:3000, the homepage address I got instead is
http://localhost:3000/#!/
我期望的地方
http://localhost:3000/#/
当我单击注册"链接时,我得到的地址是
And when I clicked on the 'register' link, the address I got is
http://localhost:3000/#!/#%2Fregister
在我期望的地方
http://localhost:3000/#/register
那正常吗?也许是我使用的Angular版本的bcs?
Is that normal? Maybe it's bcs of the version of Angular I was using?
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular-route.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular-resource.min.js"></script>
之前一切都很好,但是后来我剥离了HTML,使主页一页一页地拉动各个HTML页面,然后发生了这种情况.
It was all fine before, but then I stripped down the HTML and make the main page pull individual HTML pages one-by-one then this happened.
推荐答案
将链接从<a href="#/login">
更改为<a href="#!/login">
,将<a href="#">
更改为<a href="#!">
等.
Change your links from <a href="#/login">
to <a href="#!/login">
, <a href="#">
to <a href="#!">
etc..
我也遇到这个问题,但是从哈希更改为hashbang可以为我解决此问题.
I also have this issue but changing from a hash to hashbang resolves it for me.
这篇关于角路由ngRoute无法提取我的其他HTML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!