.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.

share|improve this question

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.

share|improve this answer
    
I tried this $stateHelperProvider.setNestedState({ name: 'app', templateUrl: 'index.html', children: [ { name: 'dashboard', templateUrl: 'dashboard/index.html', } ] }); it doesn't work too – Maria Jane 20 hours ago

You can't declare index.html as your firststate like @jakeblues said.

Try to put all the specific content from index.html in a new template :

.state('home', {
      url: '/',
      templateUrl: 'home.html',
      controller: 'homeCtrl'
 })
.state('dashboard', {
      url: '/dashboard',
      templateUrl: 'dashboard/index.html',
      controller: 'dashboardCtrl'
 })
share|improve this answer
    
I want to put my style in home.html – Maria Jane 19 hours ago
    
could you explain what you mean ? – DMCISSOKHO 18 hours ago
    
I want to load dashboard/index.html within layout.html, and dashboard/index.html should not contain any css or js, those should be in layout.html – Maria Jane 18 hours ago

I downloaded your code from the repo.

The main problem I am seeing is that your angular code is not being loaded when you do example.com/dashboard

app.use(express.static(path.join(__dirname, 'public')));

This makes your public folder as the folder from which the project is being loaded.

When you do example.com, Your angular code is loaded because you are responded with public/index.html file which contains angular code and it is correct.

But when you do example.com/dashboard, it is actually loading html file /public/dashboard/index.html where there is no any angular code.

Try doing alert on dashboardCtrl.js. You will get nothing because it is not being loaded. It is only included in index.html file which is not loaded at all.

Try changeing url to dashboards and remove 'home.dashboard'

.state('dashboard', {
  url: '/dashboards',
  templateUrl: 'dashboard/index.html',
  controller: 'dashboardCtrl'
 })
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.