pandagirl pandagirl - 3 months ago 13
CoffeeScript Question

Ember manual url change does not load page

I have an EmberJS application using Coffeescript and Ember 2.7.1.

I redirect the

/
to
/student
.

When I open my application, let's say on
www.something.com/~somebody/dist/
(yes, I need the
~somebody/dist
part), it goes to
www.something.com/~somebody/dist/student
as expected.

I also have other pages, for example
/settings
. If I use a
link-to
helper to go to the settings page, it works. When I manually change the url from
www.something.com/~somebody/dist/student
to
www.something.com/~somebody/dist/settings
, it doesn't load the page.

I get a Failed to load resource: the server responded with a status of 404 (Not Found) error.

Any idea how to fix this?

My router.coffee file:

`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`


My routes/index.coffee file:

`import Ember from 'ember'`

IndexRoute = Ember.Route.extend
beforeModel: ->
@transitionTo('student')

`export default IndexRoute`


My routes/settings.coffee file:

`import Ember from 'ember'`

SettingsRoute = Ember.Route.extend()

`export default SettingsRoute`


My routes/student.coffee file:

`import Ember from 'ember'`

StudentRoute = Ember.Route.extend()

`export default StudentRoute`


My environment.js file:

/* 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;
};

Answer

At the end I solved the problem with setting the locationType to hash in environment.js. locationType: 'hash'

http://emberjs.com/api/classes/Ember.Location.html#toc_hashlocation