Nested ui-router state without nested view?

后端 未结 2 1519
萌比男神i
萌比男神i 2021-02-08 03:53

I\'m wondering if it\'s possible to have a nested state without a nested view. Suppose I have this setup:

App.config(function($stateProvider, $urlRouterProvider)         


        
2条回答
  •  时光说笑
    2021-02-08 04:34

    Sure, just because a state shares part of the url doesn't mean it has to be a parent/child relationship. Just set the us state's url to /about/us and don't give it a parent.

    App.config(function($stateProvider, $urlRouterProvider) {
        //
        //
        // Now set up the states
        $stateProvider
        .state('index', {
            url: "/index",
            templateUrl: "views/home.html",
            controller: "MainController",
            ncyBreadcrumb: {
                label: 'Home'
            }
        })
        .state('About', {
            url: "/about",
            templateUrl: "views/about.html",
            controller: "AboutController",
            ncyBreadcrumb: {
                label: 'About',
                parent: 'index'
            }
        })
        .state('us', {
            url: "/about/us",
            templateUrl: "views/us.html",
            controller: "UsController",
            ncyBreadcrumb: {
                label: 'Us'
            }
        })
        //
        // For any unmatched url, redirect to /home
        $urlRouterProvider.otherwise("/index");
    });
    

提交回复
热议问题