0

I have a few simple states set up as well as a default state for invalid URLs.

$stateProvider
    .state('visitor', {
        url: '/visitor',
        templateUrl: '/visitor/register.html',
        controller: 'RegisterController'
    })
    .state('member', {
        url: '/member',
        templateUrl: '/member/login.html',
        controller: 'AuthController'
    });

 $urlRouterProvider.otherwise('/visitor');

In the case of an invalid URL, I'd like to be able to capture it and then pass it along to the default state's controller so that I can log it somewhere, display it to the user once they've been redirected to the default view, whatever....

Aside from the URL matching, is there any object through which that invalid URL would be exposed?

There is the $stateNotFound event that would be perfect if it fired in the case of invalid URLs being requested as well as states. Alas, this does not seem to be the case.

Daveh0
  • 952
  • 9
  • 33
  • Not sure, why the $stateNotFound is not working for you, but here you can check another way how to do that http://stackoverflow.com/q/23298021/1679310 – Radim Köhler Apr 21 '15 at 10:45

1 Answers1

0

As i look at ui-router documentation there is an event

$stateNotFound that is raised when state is not found. Can you see if it is helpful. Here is what the ui-router help states:

$stateNotFound - v0.3.0 - fired when a requested state cannot be found using the provided state name during transition. The event is broadcast allowing any handlers a single chance to deal with the error (usually by lazy-loading the unfound state).

Chandermani
  • 42,589
  • 12
  • 85
  • 88
  • Thanks for the response. Yes I saw this when I first started with ui-router. Unfortunately, it only seems to work when an actual state (as opposed to a url) is requested. In my case, the invalid requests (that I am concerned with) will be in the form of a URL or relative path. – Daveh0 Apr 21 '15 at 09:39