Ember应用程序在localhost URL

时间:2017-01-20 12:08:06

标签: javascript ember.js ember-cli

在我的Ember应用程序(基于引擎)中,我没有在localhost URL中看到哈希

我确实尝试在environment.js中更改locationType

locationType:'hash'

虽然路由&一切正常,我只是想知道如何在地址栏网址中获得#。

以下是我的完整环境.js

/*jshint node:true*/
'use strict';

module.exports = function(environment, appConfig) {
    console.log(environment);
      var ENV = {
            modulePrefix: 'myapp-ui',
            environment: environment,
            rootURL: '/myapp/',
            locationType: 'auto',
            EmberENV: {
              FEATURES: {
                // Here you can enable experimental features on an ember canary build
                // e.g. 'with-controller': true
              },
              EXTEND_PROTOTYPES: {
                // Prevent Ember Data from overriding Date.parse.
                Date: false
              }
            },

            APP: {
              // Here you can pass flags/options to your application instance
              // when it is created
            },
            TRACKING_ENABLED: true,
            LOG_TRACKING_ENABLED: false,
            ROUTE_TRANSITION_TRACKING_ENABLED: false,
            LOG_ERROR_TRACKING: true,
            ANALYTICS_URL:"X",
            ANALYTICS_SITE_ID:0,
            STUB_MODE : false,
            SET_LOCALE : true
          };
    if (environment && environment !== 'development') {
        ENV.rootURL = "";
    }
  return ENV;
};

2 个答案:

答案 0 :(得分:1)

将您的<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app = "app"> <div ng-controller = "AppCtrl as ctrl1"> {{ctrl1.getSearchQuery()}} </div> <div ng-controller = "AppCtrl as ctrl2"> <input type="search" ng-model = "ctrl2.variable" ng-change="ctrl2.setSearchQuery()"/> {{ctrl2.variable}} </div> </div> config/environment.js配置选项更新为locationType重新启动您的Ember服务器。

hash

引自Ember guies,

  

您可以在locationType: 'hash', // inside ENV 下的config / environment.js中更改此选项。

https://guides.emberjs.com/v2.2.0/configuring-ember/specifying-url-type/

答案 1 :(得分:0)

在应用根目录的“Router.js”文件中添加以下代码行:

Router.reopen({
    location: 'hash'
});

有关哈希的更多信息:HASHLOCATION ember

然后转到localhost:4200/#/