Ember 手动 url 更改不加载页面
Ember manual url change does not load page
我有一个使用 Coffeescript 和 Ember 2.7.1 的 EmberJS 应用程序。
我将 /
重定向到 /student
。
当我打开我的应用程序时,假设在 www.something.com/~somebody/dist/
(是的,我需要 ~somebody/dist
部分),它会按预期转到 www.something.com/~somebody/dist/student
。
我还有其他页面,比如/settings
。如果我使用 link-to
助手转到设置页面,它就可以工作。当我手动将 url 从 www.something.com/~somebody/dist/student
更改为 www.something.com/~somebody/dist/settings
时,它不会加载页面。
我收到 加载资源失败:服务器响应状态 404(未找到) 错误。
知道如何解决这个问题吗?
我的router.coffee文件:
`import Ember from 'ember'`
`import config from './config/environment'`
Router = Ember.Router.extend
location: config.locationType,
rootURL: config.rootURL
Router.map ->
@route 'student'
@route 'settings'
@route 'statistics'
@route 'directory'
`export default Router`
我的routes/index.coffee文件:
`import Ember from 'ember'`
IndexRoute = Ember.Route.extend
beforeModel: ->
@transitionTo('student')
`export default IndexRoute`
我的routes/settings.coffee文件:
`import Ember from 'ember'`
SettingsRoute = Ember.Route.extend()
`export default SettingsRoute`
我的routes/student.coffee文件:
`import Ember from 'ember'`
StudentRoute = Ember.Route.extend()
`export default StudentRoute`
我的environment.js文件:
/* jshint node: true */
module.exports = function(environment) {
var ENV = {
modulePrefix: 'something-frontend',
environment: environment,
rootURL: '/',
locationType: 'auto',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
}
},
APP: {
// Here you can pass flags/options to your application instance
// when it is created
}
};
if (environment === 'development') {
// ENV.APP.LOG_RESOLVER = true;
// ENV.APP.LOG_ACTIVE_GENERATION = true;
// ENV.APP.LOG_TRANSITIONS = true;
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
// ENV.APP.LOG_VIEW_LOOKUPS = true;
}
if (environment === 'test') {
// Testem prefers this...
ENV.baseURL = '/';
ENV.locationType = 'none';
// keep test console output quieter
ENV.APP.LOG_ACTIVE_GENERATION = false;
ENV.APP.LOG_VIEW_LOOKUPS = false;
ENV.APP.rootElement = '#ember-testing';
}
if (environment === 'production') {
ENV.location = 'hash';
ENV.rootURL = '/~somebody/dist'
}
return ENV;
};
你需要有一个设置路由让你的应用程序去。请确保您有 routes/settings.js 文件。
这不是 ember 的问题,而是 http 服务器配置的问题。您应该将您的 http 服务器配置为将所有与文件不匹配的请求重定向到 index.html.
在 nginx 中,您可以使用以下内容:
location /~user/dist/ {
try_files $uri $uri/ /index.html?/$request_uri;
}
最后我通过在 environment.js 中将 locationType 设置为 hash 解决了这个问题。
locationType: 'hash'
http://emberjs.com/api/classes/Ember.Location.html#toc_hashlocation
我有一个使用 Coffeescript 和 Ember 2.7.1 的 EmberJS 应用程序。
我将 /
重定向到 /student
。
当我打开我的应用程序时,假设在 www.something.com/~somebody/dist/
(是的,我需要 ~somebody/dist
部分),它会按预期转到 www.something.com/~somebody/dist/student
。
我还有其他页面,比如/settings
。如果我使用 link-to
助手转到设置页面,它就可以工作。当我手动将 url 从 www.something.com/~somebody/dist/student
更改为 www.something.com/~somebody/dist/settings
时,它不会加载页面。
我收到 加载资源失败:服务器响应状态 404(未找到) 错误。
知道如何解决这个问题吗?
我的router.coffee文件:
`import Ember from 'ember'`
`import config from './config/environment'`
Router = Ember.Router.extend
location: config.locationType,
rootURL: config.rootURL
Router.map ->
@route 'student'
@route 'settings'
@route 'statistics'
@route 'directory'
`export default Router`
我的routes/index.coffee文件:
`import Ember from 'ember'`
IndexRoute = Ember.Route.extend
beforeModel: ->
@transitionTo('student')
`export default IndexRoute`
我的routes/settings.coffee文件:
`import Ember from 'ember'`
SettingsRoute = Ember.Route.extend()
`export default SettingsRoute`
我的routes/student.coffee文件:
`import Ember from 'ember'`
StudentRoute = Ember.Route.extend()
`export default StudentRoute`
我的environment.js文件:
/* jshint node: true */
module.exports = function(environment) {
var ENV = {
modulePrefix: 'something-frontend',
environment: environment,
rootURL: '/',
locationType: 'auto',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
}
},
APP: {
// Here you can pass flags/options to your application instance
// when it is created
}
};
if (environment === 'development') {
// ENV.APP.LOG_RESOLVER = true;
// ENV.APP.LOG_ACTIVE_GENERATION = true;
// ENV.APP.LOG_TRANSITIONS = true;
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
// ENV.APP.LOG_VIEW_LOOKUPS = true;
}
if (environment === 'test') {
// Testem prefers this...
ENV.baseURL = '/';
ENV.locationType = 'none';
// keep test console output quieter
ENV.APP.LOG_ACTIVE_GENERATION = false;
ENV.APP.LOG_VIEW_LOOKUPS = false;
ENV.APP.rootElement = '#ember-testing';
}
if (environment === 'production') {
ENV.location = 'hash';
ENV.rootURL = '/~somebody/dist'
}
return ENV;
};
你需要有一个设置路由让你的应用程序去。请确保您有 routes/settings.js 文件。
这不是 ember 的问题,而是 http 服务器配置的问题。您应该将您的 http 服务器配置为将所有与文件不匹配的请求重定向到 index.html.
在 nginx 中,您可以使用以下内容:
location /~user/dist/ {
try_files $uri $uri/ /index.html?/$request_uri;
}
最后我通过在 environment.js 中将 locationType 设置为 hash 解决了这个问题。
locationType: 'hash'
http://emberjs.com/api/classes/Ember.Location.html#toc_hashlocation