dotJEM / angular-routing

Enhanced state based routing for Angular applications!
https://dotjem.github.io/angular-routing/
MIT License
75 stars 9 forks source link

When using RouteProvider separately to the StateProvider, state not updated on route param change #128

Open mcampster opened 9 years ago

mcampster commented 9 years ago

When defining a state independently of the route e.g. define the state with the $stateProvider, then map the route to the state using the $routeProvider, the state is not correctly reloaded when one of the route params changes e,g

$stateProvider.state('contact', {
                views: {
                    'main': {
                        template: 'contact.html',
                        controller: 'contactController'
                    }
                },
            })

$routeProvider.when('/contacts/:contactId', { state: 'contact') })

I would expect that when the 'contactId' changes, the state should be reloaded, as it is when you declare the route on the state itself...

$stateProvider.state('contact', {
                route: '/contacts/:contactId',
                views: {
                    'main': {
                        template: 'contact.html',
                        controller: 'contactController'
                    }
                },
            })

The reason I am declaring the routes using the routeProvider is so that we can map 1 or more routes to the same state. If there is another way of doing this, perhaps the above issue would not need solving?

jeme commented 9 years ago

reproduced: http://plnkr.co/edit/SQbnUw766OhRQ8rasmOT?p=preview

jeme commented 9 years ago

There is still a piece missing in this on for it to work with no routes on the state at all.

But for the more conceptual part, I would still recommend giving a route to an actual state... Which will act as a main route for that state... Reason being that it enables URL generation for states...

You can still add additional routes pointing to the state after that. So in essence you would have:

$stateProvider.state('contact', {
                route: '/contacts/:contactId',
                views: {
                    'main': {
                        template: 'contact.html',
                        controller: 'contactController'
                    }
                },
            })

$routeProvider.when('/anotherurl/:contactId', { state: 'contact') })
jeme commented 9 years ago

and Example: http://plnkr.co/edit/UtuBVXrr89cizzqz4IFU?p=preview (Running current latest from master, I wan't this issue fully fixed before I do a release)