因此,在四处浏览MEAN之后,我决定制作我的第一个MEAN应用程序,该应用程序非常小,除了路由使我的应用程序成为一页应用程序之外,其他所有功能似乎都可以使用。任何帮助将非常感激!

 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'
     });
 });


无论如何,我采用了样板导航栏

       <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上运行它时,我得到的主页地址是

 http://localhost:3000/#!/


我期待的地方

 http://localhost:3000/#/


当我点击“注册”链接时,我得到的地址是

 http://localhost:3000/#!/#%2Fregister


如我所料

 http://localhost:3000/#/register


那是正常的吗?也许是我使用的Angular版本的bcs?

<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页面,然后发生了这种情况。

最佳答案

将链接从<a href="#/login">更改为<a href="#!/login">,将<a href="#">更改为<a href="#!">等。

我也有这个问题,但是从哈希更改为hashbang可以为我解决。

09-25 18:20
查看更多