簡體   English   中英

angularjs UI路由器URL不起作用

[英]angularjs ui-router url not working

我在Angularjs中使用ui-router進行嵌套路由,但工作正常,但是有一個問題,當我刷新頁面或手動直接輸入url時,我得到一個錯誤:在此未找到請求的URL / home / general服務器。 我的應用代碼是:

angular.module("app",["ui.router"])
.controller("appController",["$scope", function($scope){}])
.config(function($stateProvider, $urlRouterProvider,$locationProvider){
        $stateProvider
            .state('home', {
                url: "/",
                templateUrl: "/library/ngTemplates/home.html"
            })
            .state('home.general', {
                url: "home/general",
                templateUrl: "/library/ngTemplates/home-general.html"
            })
            .state('home.lifeStyle', {
                url: "home/life-style",
                templateUrl: "/library/ngTemplates/home-life-style.html"
            })
            .state('home.lifeStyle.sport', {
                url: "/sport",
                templateUrl: "/library/ngTemplates/home-life-style-sport.html"
            })
            .state('home.lifeStyle.economic', {
                url: "/economic",
                templateUrl: "/library/ngTemplates/home-life-style-economic.html"
            });
            $locationProvider.html5Mode(true);
});

你應該改變

url: "home/general"

url: "/home/general"

最初的反彈是阻礙您進行路由的原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM