Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ui-router Why parent states must be abstract

Why parent views have to be abstract in order to have child views (nested views) rendered?

$stateProvider
            .state('A', {url: '/A', abstract: true, templateUrl: 'views/A.html'})
            .state('A.B', {url: '', abstract: true, templateUrl: 'views/B.html'})
            .state('A.B.C', {url:'', abstract:false, templateUrl:'views/C.html'});

The parent view 'A' is hosted in home.html as follow:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Yomingo</title>
    <link href="lib/bootstrap/css/bootstrap.css" rel="stylesheet"/>
    <link href="lib/bootstrap/css/bootstrap-responsive.css" rel="stylesheet"/>
</head>
<body>
    <div ui-view>
    </div>
<script type="text/javascript" data-main="scripts/main" src="lib/require/require.js"></script>
</body>
</html>

If any of the parent states 'A' or 'B' is marked as abstract=false the ui-view content is not rendered.

like image 936
Mihai H Avatar asked May 03 '13 16:05

Mihai H


1 Answers

I've been having similar trouble.

Your three states are all using the same URL, /A:

  • A: '/A'
  • A.B: '/A' + ''
  • A.B.C: '/A' + '' + ''

As they have URLs defined, the current state will be chosen based on your current URL. You can only be in one state at a time, so presumably the state that is chosen is the one defined first.

If you make the A and A.B states abstract then they cannot be transitioned into and so will not be considered when you browse to /A. Thus A.B.C is chosen, inheriting from A.B and A.

If you are looking to show more that one of your views at a time then I would recommend reading the docs for multiple named views to make it easier to keep track of.

like image 69
Andyrooger Avatar answered Oct 19 '22 09:10

Andyrooger