【问题标题】:Multiple AngularJS apps on same server同一台服务器上的多个 AngularJS 应用程序
【发布时间】:2015-07-12 05:24:58
【问题描述】:

我正在尝试将 2 个(或更多)角度应用程序放在同一个 NodeJS 服务器上。基本上我想要的是:

  • mydomain.com/clientapp - 最终用户应用程序,例如:买家
  • mydomain.com/userapp - 将创建内容的用户。例如:一个卖家和他的产品
  • mydomain.com/admin - 可以批准和删除内容的团队

我正在使用 ui-router ($stateProvider) 创建路由并加载页面。问题是我希望能够在我的应用程序上编写相对路径,这样如果我需要将基本 url 从 clientapp 重命名为 client,我不需要更改我所有的应用程序 url。

// this should be routed to admin/clients. Relative path
state('listClients', {
        url: '/clients',
        templateUrl: 'modules/clientes/views/list-clients.client.view.html'
    }).

// this is how I am currently doing. 
state('listClients', {
        url: '/admin/clients',
        templateUrl: 'modules/clientes/views/list-clients.client.view.html'
    }).

正在发生的另一件奇怪的事情是,当我将 Angular 应用程序设置为 url 时,它会杀死最后一个 / 并添加 #!直接在应用名称上:

mydomain.com/app 
becomes mydomain.com/app#!/main // ugly as hell
wanted mydomain.com/app/#!/main // little better

我该怎么做:

  • 正确设置 AngularJS 和 ui-route 以使用其所有请求的基本路径?
  • 解决难看的网址问题?

【问题讨论】:

  • 您有问题吗?
  • 是的。编辑了问题。
  • 你的 html 头部有基本的 href= 元素吗?
  • 我已经尝试过基本元素,但它似乎对某些库和#anchor 元素有一些副作用

标签: angularjs node.js


【解决方案1】:

第一个应用文件夹

  app.use('/', express.static(path.join(__dirname + '/app1')));

第二个应用文件夹

  app.use('/crm', express.static(path.join(__dirname + '/app1/app2')));

完成!享受

【讨论】:

    【解决方案2】:

    1.你可以试试ui.router.stateHelper

    angular.module('admin', ['ui.router', 'ui.router.stateHelper'])
      .config(function(stateHelperProvider){
        stateHelperProvider.setNestedState({
            name: 'admin',
          url: '/admin',
          templateUrl: 'admin.html',
          children: [
            {
              name: 'listClients',
              url: '/clients',
              templateUrl: 'clients.html'
            }
          ]
        });
      });
    

    一旦您想将模块更改为 clientapp,您只需更改模块名称和 url

    angular.module('clientapp', ['ui.router', 'ui.router.stateHelper'])
      .config(function(stateHelperProvider){
        stateHelperProvider.setNestedState({
            name: 'clientapp',
          url: '/clientapp',
          templateUrl: 'clientapp.html',
          children: [
            {
              name: 'listClients',
              url: '/clients',
              templateUrl: 'clients.html'
            }
          ]
        });
      });
    

    2.至于丑陋的问题,我不知道。对不起。

    【讨论】:

    • 您可以尝试$locationProvider of angular.js 来解决丑陋的问题。
    猜你喜欢
    • 2019-10-29
    • 1970-01-01
    • 2012-08-22
    • 2021-03-02
    • 2018-11-18
    • 2019-01-26
    • 1970-01-01
    • 1970-01-01
    • 2013-05-03
    相关资源
    最近更新 更多