Skip to content

Instantly share code, notes, and snippets.

@LeipeLeon
Last active April 1, 2019 16:12
Show Gist options
  • Save LeipeLeon/6676bd7d91a9e9fb78eb40ced76f2ed7 to your computer and use it in GitHub Desktop.
Save LeipeLeon/6676bd7d91a9e9fb78eb40ced76f2ed7 to your computer and use it in GitHub Desktop.
Ember list routes
import Ember from 'ember';
import EmberRouter from '@ember/routing/router';
import { computed } from '@ember/object';
export default Ember.Controller.extend({
appName: 'Ember Twiddle!',
myRoutes: computed('isInitialized', function(){
let owner = Ember.getOwner(this);
let router = owner.lookup('router:main');
let routes = router._routerMicrolib.recognizer.names;
console.log(routes);
// return Object.keys(routes);
return Object.keys(routes).filter(function(key) {
console.log(key === "error" )
return ! (key.match(/error/) || key.match(/loading/))
})
})
});
import EmberRouter from "@ember/routing/router";
const Router = EmberRouter.extend({});
Router.map(function() {
this.route("main", { path: "/" }, function() {
this.route("search");
this.route("live");
this.route("user", function() {
this.route("login");
this.route("forgot");
this.route("reset_password", {
path: "reset_password/:modification_code"
});
this.route("signup");
this.route("assignments");
});
this.route("info", function() {
this.route("faq");
this.route("contact");
this.route("jobs");
this.route("terms");
this.route("disclaimer");
this.route("privacy");
});
});
this.route("station", { path: "/stations/:station_id" }, function() {
this.route("events", function() {
this.route("live");
this.route("recording", { path: "/recording/:recording_id" });
this.route("event", { path: "/event/:event_id" });
});
this.route("calendar");
this.route("info");
this.route("myStations");
});
this.route("recover_password", {
path: "/recover_password/:modification_code"
});
this.route("404", { path: "/*path" });
});
export default Router;
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<ul>
{{#each myRoutes as |route|}}
<li>{{route}}</li>
{{/each}}
</ul>
<br>
<br>
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment