Reputation: 2386
I am trying to route my app for the very first time, but I don't quite understand the logic. I got my templates rendered when putting to my route.js file the following:
import Ember from 'ember';
import config from './config/environment';
var Router = Ember.Router.extend({
location: config.locationType
});
Router.map(function() {
this.route('main', { path: '/' }, function() {
this.route('helloworld', { path: '/'});
});
});
export default Router;
Most of the examples seem to route with function App.router.map. First of all I don't quite understand what is the difference? Are the routes stored inside the app or what. And when I try to add this to route.js:
import Ember from 'ember';
import config from './config/environment';
var Router = Ember.Router.extend({
location: config.locationType
});
App.Router = Ember.Router.extend({
enableLogging: true,
location: 'hash'
});
App.Router.map(function() {
this.route('main');
});
export default Router;
I get: "Uncaught ReferenceError: App is not defined". So what would be the right approach here and what am I missing out?
Upvotes: 1
Views: 1148
Reputation: 18672
Generally, there are 2 approaches to creating Ember application:
In Ember CLI you should never access global app variable. So, your router.js
should look like in your first code example.
App
isn't defined inside your router.js
, because it isn't the way to go with Ember CLI.
In Ember CLI you use modules and files split across many directories instead of 1 big file with global variable - App
.
You should learn more about fundamentals of Ember CLI and Ember. Ember Guides are the best place to start.
Upvotes: 2