Could not resolve '…' from state ''

前端 未结 6 898
名媛妹妹
名媛妹妹 2020-12-07 18:49

This is first time i am trying to use ui-router.

Here is my app.js

angular.module(\'myApp\', [\'ionic\'])

.run(function($ionicPlatform) {
  $ionicPl         


        
6条回答
  •  不知归路
    2020-12-07 19:21

    Just came here to share what was happening to me.
    You don't need to specify the parent, states work in an document oriented way so, instead of specifying parent: app, you could just change the state to app.index

    .config(function($stateProvider, $urlRouterProvider){
        $urlRouterProvider.otherwise("/index.html");
    
    $stateProvider.state('app', {
      abstract: true,
      templateUrl: "tpl.menu.html"
    });
    
    $stateProvider.state('app.index', {
        url: '/',
        templateUrl: "tpl.index.html"
    });
    
    $stateProvider.state('app.register', {
        url: "/register",
        templateUrl: "tpl.register.html"
    });
    

    EDIT Warning, if you want to go deep in the nesting, the full path must me specified. For example, you can't have a state like

    app.cruds.posts.create
    

    without having a

    app
    app.cruds
    app.cruds.posts
    

    or angular will throw an exception saying it can't figure out the rout. To solve that you can define abstract states

    .state('app', {
         url: "/app",
         abstract: true
    })
    .state('app.cruds', {
         url: "/app/cruds",
         abstract: true
    })
    .state('app/cruds/posts', {
         url: "/app/cruds/posts",
         abstract: true
    })
    

提交回复
热议问题