AngularJS force app to start from specific URL

China☆狼群 提交于 2019-12-10 18:48:00

问题


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:


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');        
})



回答2:


i think you are redirecting to page not any state. You need to mredirect to state.

$urlRouterProvider.otherwise("/state1");


来源:https://stackoverflow.com/questions/34039989/angularjs-force-app-to-start-from-specific-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!