2

I'm using angular-ui-router with HTML5 mode set to false - I use hashbang. When user hits mydomain.com I need to redirect him to mydomain.com/#/welcome, how can I do that?

I've looked through ui-router source code and when mydomain.com is hit the $location.path() is "" so this approach .when("", "/welcome") doesn't work since .when("" translates into this /^$/ regex and when "" is tested against this regex null is returned.

Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488

3 Answers3

1

This seems to be a viable solution:

appModule.run(['$location', function ($location) {

    if ($location.path() === "") {
        $location.path("/");
    }
Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488
0

Use $urlRouterProvider.otherwise to redirect to your welcome page if the current URL doesn't match any of your states.

$urlRouterProvider.otherwise('/welcome');

See this stack overflow question: Otherwise on StateProvider

Community
  • 1
  • 1
shieldstroy
  • 1,307
  • 1
  • 10
  • 24
0

If you just want to show welcome.html you can do something like below

.when('/', {
                templateUrl: 'welcome.html',
                controller: 'homeCtrl'
            })

Else if you want to redirect user to mydomain.com/#/welcome you can use window.locations or you can handle it as the part of homeCtrl where you can redirect it using $location.path('/welcome'); and below be route for it

.when('/welcome', {
                templateUrl: 'welcome.html',
                controller: 'welcomeCtrl'
            })
Rishi Saraf
  • 1,644
  • 2
  • 14
  • 27