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

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I tried this $stateHelperProvider.setNestedState({ name: 'app', templateUrl: 'index.html', children: [ { name: 'dashboard', templateUrl: 'dashboard/index.html', } ] }); it doesn't work too
0

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'
 })

3 Comments

I want to put my style in home.html
could you explain what you mean ?
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
0

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'
 })

2 Comments

so I have to put my style into dashboard/index.html?
No you don't have to put style in dashboard/index.html. Your styles can be in index.html. It is fine. Please check my response in stackoverflow.com/questions/39305398/… to deal with styles.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.