Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS force app to start from specific URL

I have a specific logic sequence in my app, and I want a simple way to force my app to start from the welcome page. I am using this:

$urlRouterProvider.otherwise('/pages/welcome');

the problem is that otherwise just play with the unknown URLs and redirect them to the welcome, whereas I want to redirect to the welcome in all cases, even in the registered states.


1 Answers

Simply try location.hash = '#/'; like the following:

angular.module('app', []).config(function ($stateProvider, $urlRouterProvider) {

    location.hash = '#/';

    $stateProvider
        .state('welcome', {
            url        : '/pages/welcome',
            templateUrl: 'views/welcome.html',
            controller : 'WelcomeCtrl'
        });

    // if none of the above states are matched, use this as the fallback
    $urlRouterProvider.otherwise('/pages/welcome');        
})
like image 63
Eymen Elkum Avatar answered Sep 18 '26 06:09

Eymen Elkum



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!