0

If I am defining a router configuration as :

export function routerConfig($stateProvider, $urlRouterProvider, $locationProvider) {
  'ngInject';
  $locationProvider.html5Mode(true);

  $stateProvider
    .state('myapp', {
      url: '/',
      templateUrl: 'app/main/main.html',
      controller: 'MainController',
      controllerAs: 'main'
    })
    .state('searchResults', {
      url: '/search',
      parent: 'myapp',
      templateUrl: 'app/search-results/search-results.html',
      controller: 'SearchResultsController',
      controllerAs: 'srchRes'

    });

  $urlRouterProvider.otherwise('/');
}

When I try hitting http://localhost/search , I am getting redirected to http://localhost. I don't know the reason why?

But this code is working :

export function routerConfig($stateProvider, $urlRouterProvider, $locationProvider) {
  'ngInject';
  $locationProvider.html5Mode(true);

  $stateProvider
    .state('myapp', {
      url: '/myapp',
      templateUrl: 'app/main/main.html',
      controller: 'MainController',
      controllerAs: 'main'
    })
    .state('searchResults', {
      url: '/search',
      parent: 'myapp',
      templateUrl: 'app/search-results/search-results.html',
      controller: 'SearchResultsController',
      controllerAs: 'srchRes'

    });

  $urlRouterProvider.otherwise('/');
}

Now when I do http://localhost/myapp/search is working perfectly.

Can't nested states be created out of states with the "url" property set to "/" root?

1 Answer 1

1

I believe that the url property is optional and if you remove it from the parent you should be able to navigate to the child without any issues

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Worked perfectly.

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.