3

I'm working on a simple angular application using ui-router. I have a couple states for selecting and then editing information about a publisher. The relevant config:

 .state('select-publisher', { url: '/select-publisher', templateUrl: '/Content/superadmin/src/templates/publishers/publishers.html' }) .state('publisher', { abstract: true, url: 'publisher/{id:int}', templateUrl: '/Content/superadmin/src/templates/publishers/publisher.html' }) .state('publisher.details', { url: '/details', templateUrl: '/Content/superadmin/src/templates/publishers/details.html' }) .state('publisher.ad-tags', { url: '/ad-tags', templateUrl: '/Content/superadmin/src/templates/publishers/ad-tags.html' }) .state('publisher.native-ads', { url: '/native-ads', templateUrl: '/Content/superadmin/src/templates/publishers/native-ads.html' }) 

Inside the select-publisher state I have a big list of available publishers. Each one of them is bound to an ng-click event that triggers the following function in my controller:

 $scope.selectPublisher = function(publisher) { publisherService.setSelectedPublisher(publisher); $state.go('publisher.details', {id: publisher.Id}); }; 

This works just fine and takes me to the publisher.details state and renders the proper view. At this point the URL in my browser points to localhost:1337/superadmin#/publisher/39/details where 39 is the ID of the publisher that I selected.

The problem is, if I refresh this page or attempt to navigate directly to it by pasting the URL into the browser from another area of the application, I am ALWAYS taken back to the select-publisher state. I would like to be able to configure my states such that I am able to navigate to the details state (or any other state) based on URL.

Worth noting is that I do have a catch all route defined after all of my states:

$urlRouterProvider.otherwise('/select-publisher'); 

I'm assuming that for some reason this is being triggered but I can't reason as to why navigation works in my app using either $state.go as I have indicated in my controller as well as using ui-sref directive in my HTML templates but not through navigating directly to the URL.

6
  • What does your complete URL look like? Commented Feb 7, 2015 at 17:01
  • It's already posted in the question Commented Feb 7, 2015 at 17:06
  • 1
    maybe it's because of missing slash url: '/publisher/{id:int}' ? Commented Feb 7, 2015 at 17:45
  • @lujcon Wow... thanks man I can't believe I didn't spot that. Somtimes you just need a second pair of eyes. If you add that as an answer I'll mark it as correct. Commented Feb 7, 2015 at 17:54
  • 3
    I'm not here to collect points ;) I'm happy I was able to help. Commented Feb 7, 2015 at 18:15

1 Answer 1

5

Maybe it's because of missing slash url: /publisher/{id:int}

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.