簡體   English   中英

AngularJS UI路由器子級到父級視圖

[英]AngularJS ui-router child to parent view

我在將子級路由到父級導航時遇到問題。

我的路由配置如下:

 templateApp.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {

//For Default Redirect
$urlRouterProvider.otherwise("/");

//For set up the states
$stateProvider
    .state('list', {
        url: "/",
        cache:false,
        templateUrl: "/Templates/TemplateList",
        controller: "templateListController"
    })
    .state('template', {
        url: "/template/:templateId",
        cache: false,
        templateUrl: "/Templates/MainTemplate",
        controller: "mainTemplateController"
    })
    .state('template.detail', {
        url: "/detail/:templateId",
        cache: false,
        templateUrl: "/Templates/TemplateDetails",
        controller: "templateDetailController"
    })
    .state('template.section', {
        url: "/section/:paperTemplateId",
        cache: false,
        templateUrl: "/Templates/TemplateSection",
        controller: "templateSectionController"
    })
    .state('template.summary', {
        url: "/summary/:templateId",
        cache: false,
        templateUrl: "/Templates/TemplateSummary",
        controller: "templateSummaryController"
    });

}]);

我想從“列表狀態”導航到template狀態。 我已經使用下面的代碼,它完美地工作。

    $state.go('template', { templateId: examTemplate.Id });

當我想導航到“ template.detail”狀態時,我使用了以下代碼,它運行良好。

    $state.go('template.detail', { templateId: $scope.templateId });

現在,從子“ template.detail”中,我要導航到“ to template”狀態。 所以我用下面的代碼。

        $state.go('template', { templateId: $scope.templateId });

但是此路由無效。 當我將孩子路由到父母時,能否請您告訴我該代碼的問題。

謝謝,Erandika

您的答案在於ui-router文檔 它說 :

  • $ state.go('contact.detail')-將進入contact.detail狀態

  • $ state.go('^')-將進入父狀態

  • $ state.go('^。sibling')-將進入同級狀態

  • $ state.go('。child.grandchild')-將進入孫子州

因此,請使用“ ^”符號轉到當前狀態的父狀態。

暫無
暫無

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

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