2017-02-17 126 views
0

我想在事件后重定向到另一个路由,但它只显示URL更改(http://localhost:8000/login更改为http://localhost:8000/login#/home)。我想将其更改为http://localhost:8000/home#,但我无法弄清楚如何做到这一点。而我的路线这个网址无法正常工作。AngularJs重定向到路由不正常

app.js

var app = angular.module('laravel', ['ngRoute']) 
     .constant('API_URL', 'http://localhost:8000/') 
     .config(function ($routeProvider, $locationProvider) { 

      $routeProvider 
      .when('/login', { 

       controller: 'authController', 
       templateUrl: 'resources/views/auth/login.blade.php', 
      }) 
      .when('/home', { 

       templateUrl : "resources/views/home.bade.php", 
       controller : 'homeController' 
      }) 
      .otherwise({ 
       redirectTo: '/', 
      }); 
     }); 

auth.js,包含我authController

app.controller('authController', function ($scope, $http, $location, API_URL){ 

    $scope.login = function(){ 

     var url = API_URL + "login"; 

     $http.post(url, $scope.file).success(function (response) { 
     console.log("coming in homepage!!"); 
      // sessionStorage.setItem('user', $scope.user); 
      $location.path('/home'); 
     }); 
    } 
}); 

上面的代码只是http://localhost:8000/login将URL转换到http://localhost:8000/login#/home

回答

0

我明白了。 如果您将$ location配置为使用html5Mode(history.pushState),则需要使用标记指定应用程序的基本URL,或者将$ locationProvider配置为不需要基本标记,方法是将定义对象与requireBase:false一起传递给$ locationProvider.html5Mode():

$locationProvider.html5Mode({ enabled: true, requireBase: false}); 
//$locationProvider.html5Mode(true); //if we want to remove html5mode requirebase. 
0

都需要这样的我猜

$location.path('/home').replace(); 

东西,你可以检查API doc为$位置。

+0

感谢您的回复,但我已经尝试过,结果相同。 –