2017-09-14 159 views
1

當我有角的設置路由是這樣的:角路由缺少尾隨斜線

$stateProvider 
    .state('loginHome', 
    { 
    url: "/", 
    templateUrl: "scripts/features/account/views/login.html" 
    }) 
    .state('login', 
    { 
    url: "/login", 
    templateUrl: "scripts/features/account/views/login.html" 
    }) 

所以,當用戶瀏覽到:

http://localhost/MyApp/ 
http://localhost/MyApp/login 

登錄視圖渲染

如何設置路線,當用戶輸入以下URL時,它將導航它們以登錄:

http://localhost/MyApp (no trailing slash) 

回答

0

爲什麼不使用otherwise()函數$urlRouterProvider,請在app.config內部包含$urlRouterProvider。這樣所有其他無法識別的路由都會發送到登錄頁面!另外還有兩個登錄頁面的狀態,而不是你可以給它的。

JS:

$urlRouterProvider.otherwise('/'); 
$stateProvider 
    .state('login', 
    { 
    url: "/login", 
    templateUrl: "scripts/features/account/views/login.html" 
    })