vendredi 20 octobre 2017

EmberJS 2 Dynamic Routing

I'm trying to setup a way to define routes, their template and model dynamically. (Ember 2.16.0)

So far I have this:

// app/router.js
Router.map(function () {

    let routes = [
        {route: "page_one", templateName: "default.hbs"},
        {route: "page_two", templateName: "default.hbs"},
        {route: "page_three", templateName: "custom.hbs"}
    ];

    routes.forEach(function (key) {
        this.route(key.route);
    }, this);
});

This works, and allows me to load pages if their template file exists.

I want to take this a step further and define the template name here, for example I want them all to use "default.hbs" as well as load the model for them dynamically.

Is this something that's possible in EmberJS? If so which documentation should I be looking at to do so.

I'm aware you can specify templates in their corresponding route file "app/routes/page_one.js" but this wouldn't be dynamic.




Aucun commentaire:

Enregistrer un commentaire