Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs nested routing doesn't load layout

.state('home', {
      url: '/',
      templateUrl: 'index.html',
      abstract:true
 })
.state('home.dashboard', {
      url: '/dashboard',
      templateUrl: 'dashboard/index.html',
      controller: 'dashboardCtrl'
 })

I failed to load index.html when I visit example.com/dashboard, I was only able to get the raw html of what is inside dashboard/index.html. That's strange, because in index.html I've declared <ui-view></ui-view> within the body so I expect dashboard/index.html to be a child of index.html.

Pushed a repo of my code.

like image 287
Maria Jane Avatar asked Jun 15 '26 11:06

Maria Jane


1 Answers

You don't actually have nested states; you simply have a primary index.html file that serves as the container for your application, its dependencies, and your views. Angular won't load your primary index.html page, the index.html page loads Angular.

So there is no need for your 'home' state to have a templateUrl. You will use nested states if, for example, your dashboard view has an inner view that can load different templates depending on a user action. See Angular UI Router's documentation for some example use cases for nested views.

like image 176
Nate Vaughan Avatar answered Jun 18 '26 00:06

Nate Vaughan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!