Skip to content

Instantly share code, notes, and snippets.

@michalsnik
Created April 20, 2017 14:04
Show Gist options
  • Save michalsnik/3e6d9aa7cf83d304cbfb31c3c95aeda8 to your computer and use it in GitHub Desktop.
Save michalsnik/3e6d9aa7cf83d304cbfb31c3c95aeda8 to your computer and use it in GitHub Desktop.
route-lang
import Ember from 'ember';
import loadInitializers from 'ember-load-initializers';
import Resolver from './resolver';
import config from './config/environment';
import RouteAliasResolver from 'ember-route-alias/mixins/route-alias-resolver';
const { Application } = Ember;
Ember.MODEL_FACTORY_INJECTIONS = true;
const App = Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
Resolver: Resolver.extend(RouteAliasResolver),
});
loadInitializers(App, config.modulePrefix);
export default App;
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('app', { path: '/' }, function() {
this.route('news', function() {
this.route('details', { path: ':news_id' });
});
});
this.alias('en', '/en', 'app');
this.alias('de', '/de', 'app');
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
model(params) {
return params.news_id;
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return [{
id: 1,
title: 'lorem',
}, {
id: 2,
title: 'lorem',
}, {
id: 3,
title: 'dolor',
}];
}
});
<h3>Current news number: {{model}}</h3>
<h1>News</h1>
{{outlet}}
<ul>
{{#each model as |item|}}
<li>
{{#link-to 'app.news.details' item.id}}
#{{item.id}} {{item.title}}
{{/link-to}}
</li>
{{/each}}
</ul>
{{#link-to 'app'}}
go home
{{/link-to}}
<br>
Select lang:
<ul>
<li>
{{#link-to 'app'}}
PL
{{/link-to}}
</li>
<li>
{{#link-to 'en'}}
EN
{{/link-to}}
</li>
<li>
{{#link-to 'de'}}
DE
{{/link-to}}
</li>
</ul>
{{#link-to 'app.news'}}
Go to news
{{/link-to}}
{{outlet}}
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1",
"ember-route-alias": "0.1.5"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment