1

I'm using Angular-ui-router's $stateProvider to navigate in my app. The routes are defined like so (only relevant parts are shown):

function config($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/dashboard');

    $stateProvider
        .state('common', {
            url: '/',
            abstract: true,
            templateUrl: folderDictionary.common + 'content.html'
        })
        .state('common.dashboard', {
            url: 'dashboard',
            templateUrl: folderDictionary.dashboard + 'dashboard.html',
            controller: 'DashboardController'
        })
        .state('common.news', {
            url: 'news',
            templateUrl: folderDictionary.news + 'news.html',
            controller: 'NewsController'
        })
        .state('common.news_edit', {
            url: 'news/edit',
            templateUrl: folderDictionary.news + 'news_edit.html',
            controller: 'NewsEditController'
            params: {newsItem:null}
        })
        .state('common.news_add', {
            url: 'news/add',
            templateUrl: folderDictionary.news + 'news_edit.html',
            controller: 'NewsEditController'
        });
}

config.$inject = ['$stateProvider', '$urlRouterProvider'];

angular
    .module('admin.core')
    .config(config);

Navigating to the different news-states is handled in the controllers using $state.go():

$scope.edit = function(id) {
    var item = $filter('filter')($scope.news, { Id: id })[0];
    $state.go('common.news_edit', { newsItem: item });
}

$scope.add= function() {
    $state.go('common.news_add');
}

All states work fine, except for common.news_edit. Whenever I try to navigate to that route, it redirects to the route defined in $urlRouterProvider.otherwise().

When I remove $urlRouterProvider.otherwise(), the common.news_edit state works.

I suppose the $stateParams are causing this, but I'm not sure how to solve this? I don't want to pass the newsItem object in the url.

Benjamin
  • 1,983
  • 23
  • 33
  • 1
    please see this http://stackoverflow.com/questions/13832529/how-to-config-routeprovider-and-locationprovider-in-angularjs – Hadi J May 29 '16 at 15:23
  • @SSH, the html5mode did the trick, apparently. Feel free to add it as an answer and elaborate, I'll accept it as soon as I can. – Benjamin May 29 '16 at 15:35

0 Answers0