1

I am using ui-router and state provider to route the pages in my application. I have following states written in state provider.

.state('home', { url: '/home', templateUrl: 'public/msStream/stateFiles/stateHome.html', controller: 'stateHomeController' }) .state('home.profile', { url: '/home/profile', templateUrl: 'public/msStream/views/setting/ProfileBody.html' }) 

When I am in home state. /home is added in my URL, but when I switch to home.profile state using $state.go("home.profile), my URL is not changing to /home/profile but HTML page added in templateurl of the same state is getting rendered on front.

I tried adding /profile and /home/profile in the URL of the state but nothing seems to work. What am I missing here?

1
  • You're not providing enough information to answer this question. Add this to your code and see if there's an error changing state: pastebin.com/vvpQJ2E5 Commented Jan 15, 2015 at 19:02

1 Answer 1

3

I created working plunker here

The paren-child states do inherit a lot. Among other things, also the url. So we should not use for child the url part coming from parent.

$stateProvider .state('home', { url: '/home', templateUrl: 'public/msStream/stateFiles/stateHome.html', controller: 'stateHomeController' }) .state('home.profile', { // HERE // instead of this // url: '/home/profile', // we need this url: '/profile', templateUrl: 'public/msStream/views/setting/ProfileBody.html' }) 

Also very improtant note - parent must contain anchor/target/ui-view for its child:

public/msStream/stateFiles/stateHome.html

<div> <h2>this is the home</h2> placeholder for child: <hr /> <div ui-view=""></div> </div> 

The most important here is the <div ui-view=""></div> - a placeholder for child view (unnamed)

Check it in action here

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.