zoukankan      html  css  js  c++  java
  • angular 的ui.router 定义不同的state 对应相同的url

    Angular UI Router: Different states with same URL?

    The landing page of my app has two states: home-publichome-logged-in. Now I want to show both states on the same URL, but let the controller and template depend on the user session (is the user logged in or not?).

    Is there a way to achieve this?

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    You could have a base state that controls which state to load, and you could simply have the child stated of that base state not have urls:

    .state('home', {
      url: "/home",
      templateUrl: "....",
      controller: function($scope,$state,authSvc) {
         if(authSvc.userIsLoggedIn()){
              $state.go('home.loggedin')
         }else{
              $state.go('home.public')
         }
      }
    })
    
    
    .state('home.public', {
      url: "",
      templateUrl: "....",
      controller: function($scope) {
         ...........
      }
    })
    
    .state('home.loggedin', {
      url: "",
      templateUrl: "....",
      controller: function($scope) {
         ...........
      }
    })

    Now in the controller of your base state (home) you can check if the user is logged in or not, and use $state.go() to load an appropriate state.

  • 相关阅读:
    .NET 4.0 中的契约式编程
    DELL安装Windows Server 2019
    Mysql 5.7.34免安装版本
    MQTT
    WPF属性
    WPF数据绑定
    git系列之(五)git stash 命令
    Vue.js
    git 对比两个分支差异
    TPL 之二 TransformBlock
  • 原文地址:https://www.cnblogs.com/oxspirt/p/7995043.html
Copyright © 2011-2022 走看看