1

I have a route provider like this

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 is the first page of my app.

But after login, on reloading any page that will ends up in the login.html page

I want other pages keep alive on refresh and login.html as my opening page

2 Answers 2

1

Reloading page will recreate $rootScope every time. So you need to store login details in any storage like localstorage.

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

This link might help you. you need to store data once you successfully logged in. and get stored data and validate the use while resolving url.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the comment, If there is any working example links? Please
youtube.com/… this might be helpful
@RavisankarR Please mark it as answer if it works for you
it's angular 2, i'm using angular 1
Yes but use of localstorage or session storage would be same.
0
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');
    });

Try something like this.

3 Comments

In that link also if you reload the about page, it will redirect to home page.
Download and check in local. It's nt redirecting to home
Yeah, but it's just hash tag routing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.