简体   繁体   中英

Changing only one of multiple named, nested routes

I have a template with multiple named, nested views:

template 1:

<body>
    <div ui-view></div>
</body>

template 2:

<header></header>
<div ui-view="left"></div>
<div ui-view="canvas"></div>
<div ui-view="right"></div>

and I have the following config setup:

    .state("metricDashboard", {
        url: "/metric-dashboard",
        css: { href: "core/metric-dashboard/style.css" },
        views: {
            "": {
                templateUrl: "core/metric-dashboard/view.html",
                controller: 'MetricDashboard',
            },
            "left@metricDashboard": {
                templateUrl: "core/metric-dashboard/partials/left.html",
                controller: "MetricDashboardLeft",
            },
            "canvas@metricDashboard": {
                templateUrl: "core/metric-dashboard/partials/canvas.html",
                controller: "MetricDashboardCanvas"
            },
            "right@metricDashboard": {
                templateUrl: "core/metric-dashboard/partials/right.html",
                controller: "MetricDashboardRight"
            }
        }
    })

How would I go about changing an individual route? For example, If I wanted to change "left@metricDashboard", but leave the "canvas" and "right" routes alone. I cannot seem to find a syntax without creating a new state and explicitly declaring all the routes over again.

Ok I'm guessing you want to create another state that will change only one of the views not all of them.

Let's call it left and make it a child of metricsDashboard

.state("metricDashboard", {
    url: "/metric-dashboard",
    css: { href: "core/metric-dashboard/style.css" },
    views: {
        "": {
            templateUrl: "core/metric-dashboard/view.html",
            controller: 'MetricDashboard',
        },
        "left@metricDashboard": {
            templateUrl: "core/metric-dashboard/partials/left.html",
            controller: "MetricDashboardLeft",
        },
        "canvas@metricDashboard": {
            templateUrl: "core/metric-dashboard/partials/canvas.html",
            controller: "MetricDashboardCanvas"
        },
        "right@metricDashboard": {
            templateUrl: "core/metric-dashboard/partials/right.html",
            controller: "MetricDashboardRight"
        }
    }
})
.state("metricDashboard.left", {
    url: "left",
    views: {
        "left@metricDashboard" : {
            templateUrl: "some.html",
            controller: "AwesomeCtl",
            controllerAs: "awe"
        }
    }
})

Now when you enter that state only the left view will change the others will remain as defined in the parent state metricDashboard .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM