Reputation: 81
I'm trying to create a structure for creating, reading, updating and destroying that consists on indenting params:
/items/create
/items/1/view || /items/1/edit || /items/1/remove
The states for those are like this in $stateProvider
:
.state('items.create', {
url: '/create',
templateUrl: 'item/create.html'
})
.state('items.item', {
abstract: true,
url: '/:_id',
templateUrl: 'item/itembody.html'
})
.state('items.item.view', {
url: '/view',
templateUrl: 'item/item.html'
})
.state('items.item.edit', [... and so on ...]
I'm also redirecting /1
to /1/view
using $urlRouterProvider
:
.when('/items/:_id', '/items/:_id/view');
Problem is when trying to reach /items/create
I'm being redirected to /items/create/view
. Is there a way to protect or make an exception to this word so I can reach its URL?
Upvotes: 2
Views: 99
Reputation: 182
I think your problem is that the urls are being combined, like so:
Appended Routes (default)
When using url routing together with nested states the default behavior is for child states to append their url to the urls of each of its parent states.
$stateProvider
.state('contacts', {
url: '/contacts',
...
})
.state('contacts.list', {
url: '/list',
...
});
So the routes would become:
'contacts' state matches "/contacts"
'contacts.list' state matches "/contacts/list". The urls were combined.
Try using different state names.
Upvotes: 1
Reputation: 213
This is a syntax error, change this url: '/item/:_id.view'
for this url: '/item/:_id'
.
Upvotes: 0