2

I'm working on an Angular app that uses Angular UI-Router for routing and maintaining state. I am having a hard time getting my unit test to even compile. It seems that no matter what I do, I keep getting the following error:

Error: State '' is not navigable

I have the following states set up in my app, as well as the following redirects:

app.config(function($stateProvider, $urlRouterProvider) {

var paramList = '?beds&lat&lon&zoom';

$urlRouterProvider
    .when('', '/')
    .when('/', '/search')
    .when('/search', '/search/list')
    .otherwise('');

$stateProvider
    .state('search', {
        abstract: true,
        url: '/search',
        templateUrl: 'views/search.html',
        controller: 'SearchCtrl'
     })
        .state('search.list', {
            url: '/list' + paramList,
            templateUrl: 'views/search-list.html'
         })
        .state('search.map', {
            url: '/map' + paramList,
            templateUrl: 'views/search-map.html'
        })
    .state('search.listing', {
        url: '/listing/:id' + paramList,
        templateUrl: 'views/search-listing.html'
    })
    .state('favorites', {
        url: '/favorites',
        templateUrl: 'views/favorites.html'
    })
});

I've eaten up an entire day trying to get a single test to work, but no matter what approach I take, I always end up at this same error. I have an e2e test running just fine.

2 Answers 2

1

ui-router adds an internal state for '' automatically, so that is the error you are getting. I recommend adding a '/' url for a base state and change the 'otherwise' invocation to redirect to '/' instead of ''. The internal '' state is being attempted because of your .otherwise('') call. So perhaps try this:

$urlRouterProvider
.when('/', '/search')
.when('/search', '/search/list')
.otherwise('/');
Sign up to request clarification or add additional context in comments.

Comments

0

At first glance I would say it looks like the $stateProvider is telling you you need to put an empty state in there. Add this to the list of states.

state( '', { ... } )

1 Comment

I tried this, and the error I get now is Uncaught Error: State ''' is already defined from app.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.