1

I am currently trying to set up routes in my angular application. I have these states:

.state('pet', {
  url: '/pet/:petId',
  templateUrl: 'scripts/views/profile/profile.html',
  controller: 'ProfileCtrl'
})
.state('addPet', {
  url: '/pet/add',
  templateUrl: 'scripts/views/profile/edit.html',
  controller: 'ProfileFormCtrl'
})
.state('editPet', {
  url: '/pet/:petId/edit',
  templateUrl: 'scripts/views/profile/edit.html',
  controller: 'ProfileFormCtrl'
})

The problem is when I want to go on the 'addPet' state, angular is trying to call 'pet' state with 'add' as the ':petId' parameter.

So I tried to do it in a different way:

.state('pet', {
  url: '/pet',
  abstract: true
})
.state('pet.show', {
  url: '/:petId',
  templateUrl: 'scripts/views/profile/profile.html',
  controller: 'ProfileCtrl'
})
.state('pet.add', {
  url: '/add',
  templateUrl: 'scripts/views/profile/edit.html',
  controller: 'ProfileFormCtrl'
})
.state('pet.edit', {
  url: '/:petId/edit',
  templateUrl: 'scripts/views/profile/edit.html',
  controller: 'ProfileFormCtrl'
})

and it doesn't work at all.

Any suggestions ?

0

1 Answer 1

2

Change the order, keep addPet state before pet state

.state('addPet', {
  url: '/pet/add',
  templateUrl: 'scripts/views/profile/edit.html',
  controller: 'ProfileFormCtrl'
})
.state('pet', {
  url: '/pet/:petId',
  templateUrl: 'scripts/views/profile/profile.html',
  controller: 'ProfileCtrl'
})
.state('editPet', {
  url: '/pet/:petId/edit',
  templateUrl: 'scripts/views/profile/edit.html',
  controller: 'ProfileFormCtrl'
})
Sign up to request clarification or add additional context in comments.

1 Comment

You are welcome @Mencls, you can always count on stackoverflow :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.