在 angular js 中禁用页面刷新路由

Disable routing on page refresh in angular js

我有这样的路线提供商

app.config(function ($routeProvider, $locationProvider){
$locationProvider.hashPrefix('');


$routeProvider
.when('/', {
    templateUrl: 'login.html',
    controller: 'loginCtrl'
})
.when('/home', {
    resolve:{
        "check":function($location, $rootScope){
            if(!$rootScope.loggedIn){
                $location.path('/');
            }
        }
    },
    templateUrl:'home.html',
    controller: 'homeCtrl'
})
.otherwise({
    redirectTo: '/'
   });
});

login.html 是我的应用程序的第一页。

但是在登录后,重新加载任何页面都会出现在 login.html 页面

我希望其他页面在刷新时保持活动状态并且 login.html 作为我的起始页面

scotchApp.config(function($stateProvider, $urlRouterProvider, $compileProvider, $locationProvider) {
        $locationProvider.html5Mode(true);
        $compileProvider.debugInfoEnabled(false);
        // route for the home page

        $stateProvider
            .state('home', {
                url: '/home',
                templateUrl : 'pages/home.html',
                controller  : 'mainController'
            })

            // route for the about page
            .state('about', {
                url: '/about',
                templateUrl : 'pages/about.html',
                controller  : 'aboutController'
            })

            // route for the contact page
            .state('contact', {
                url: '/contact',
                templateUrl : 'pages/contact.html',
                controller  : 'contactController'
            });

            $urlRouterProvider.otherwise('home');
    });

尝试这样的事情。

每次重新加载页面都会重新创建$rootScope。因此,您需要将登录详细信息存储在本地存储等任何存储中。

http://blog.teamtreehouse.com/storing-data-on-the-client-with-localstorage

这篇 link 可能会对您有所帮助。您需要在成功登录后存储数据。并在解析 url.

时获取存储的数据并验证使用