angularjs - Redirect to different ui-router state with same url from server? -
currently have state 'home' resides @ url '/'. after user connects, 'client' state loaded, resides @ url '/' , session updated. possible make if user reloads page, 'client' state loaded instead of 'home' state? if @ different urls, have server perform redirect them both @ base url '/'. there functionality in ui-router let me achieve this?
here states:
app.config(function($stateprovider, $urlrouterprovider,$locationprovider) { $stateprovider .state('home', { url: '/', controller: 'homepageconroller homectrl', templateurl: '/views/partials/home.html', onenter: function($http,$state) { $http.post('/checkconnected') .success(function(data,status) { if (data) {$state.go('client');} }); } }) .state('client', { url: '/', controller: 'clientcontroller clientctrl', templateurl: '/views/partials/client.html' });
as can see posting check server see if client connected , doing redirect within angular application, not happy solution @ all. post takes time , home page loaded , seen user before client page shown.
one solution have considered having state called 'client redirect' reside @ '/client' , has same template 'client' state, same $state.go on enter without need of $http.post (because server redirected based on updated session). remove delay , not flash homescreen, not seem elegant.
var app = angular.module("app", [ "ui.router" ]); app.config(function ($stateprovider, $urlrouterprovider) { $urlrouterprovider.otherwise('/index'); $stateprovider .state("app", { abstract: true, url: '/app', templateurl: "views/layout/app-body.html" }) .state("index", { url: "/index", templateurl: "views/home.html", controller: 'signincontroller' }) .state("signin", { url: "/signin", templateurl: "views/pages/signin.html", controller: 'signincontroller' }) .state("signup", { url: "/signup", templateurl: "views/pages/signup.html", controller: 'signupcontroller' }) .state('app.home', { url: '/home', templateurl: 'views/home/home.html', controller: 'homecontroller' }) .state('app.dashboard', { url: '/dashboard', templateurl: 'views/dashboard/dashboard.html', controller: 'dashboardcontroller' }) .state('app.profile', { url: '/profile', templateurl: 'views/pages/profile.html', controller: 'profilecontroller' });
});
Comments
Post a Comment