Shubham Verma
Shubham Verma

Reputation: 71

Default states in ui-router

I am currently working on a web development project and I am having a problem in implementing UI-router (AngularJS).

I want to set a default state when the page loads and also default state for the child view.

If I use abstract:true method that is not the solution because when I want to again active that state it won't be possible.

Upvotes: 4

Views: 5654

Answers (2)

giladka
giladka

Reputation: 11

you need to use at $urlRouterProvider service, first inject this service, after that write $urlRouterProvider.otherwise('/otherwise').

Pay attention that the /otherwise url must be defined on a state as usual:

$stateProvider .state("otherwise", { url : '/otherwise'...})

good luck!

Upvotes: 1

Snopzer
Snopzer

Reputation: 1692

Hope this will give you answer to your Question

var App = angular.module('TechdefeatApp',['ui.router']);
App.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider){
    // For any unmatched url, send to /business
    $urlRouterProvider.otherwise("/")

    $stateProvider
    .state('/', {
        url: "/",
        templateUrl: "app/components/home/homeView.html",
        controller:"homeController"
    })
    .state('member', {
        url: "/member/:seo_url",
        templateUrl: "app/components/member/memberView.html",
        controller:"memberController"
    })
    .state('category', {
        url: "/category/:seo_url", 
        templateUrl: "app/components/category/categoryView.html",
        controller:"categoryController"
    })

}]);

Upvotes: 5

Related Questions