Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ui-router initial state without URL

Using UIRouter in an Angular 1.5 app, I'm having trouble trying to set an initial state for my angular module.

I've created a few states without URLs (because I don't need actual routing) and I would like to activate an initial state once the module is instantiated.

Usually, I would do this using $urlRouterProvider.otherwise(<initialRoute>), but since I don't use URLs in my states, that can't work.

Does UIRouter (or Angular) provide a solution for this?

like image 375
ClementParis016 Avatar asked Jul 26 '26 16:07

ClementParis016


1 Answers

After your application has bootstrapped, you can set your initial state inside the .run() method.

angular.module("myModuleName")
    .run([
        "$state",
         function($state){
            $state.go('stateName');
         }
     ]);
like image 146
Deblaton Jean-Philippe Avatar answered Jul 28 '26 07:07

Deblaton Jean-Philippe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!