0

I'm having trouble understanding how Ember.js routing works and particularly how to use Dynamic Segments from the route.

For example, if you wanted to grab the token off of a reset password page and use that in a form submission, how would you get the token? The code below attempts to print the token on a page as an intermediate step, but it won't render the TokenView. What am doing wrong? Thanks.

window.App = Em.Application.create({});

App.IndexView = Em.View.extend({
    template: Em.Handlebars.compile(
        '<h1>Index</h1>'
    )
});

App.ResetView = Em.View.extend({
    template: Em.Handlebars.compile(
        '<h1>reset view </h1>'
    )
});

App.TokenView = Em.View.extend({
    template: Em.Handlebars.compile(
        '<h1>token view {{token_id}}</h1>'
    )
});

App.Router = Ember.Router.extend({

    rootElement:'#content',
    location: 'hash',
    enableLogging: true,

    root: Ember.State.extend({

        index: Ember.ViewState.extend({
            route: '/',
            view: App.IndexView
        }),

        passwordReset: Ember.ViewState.extend({
            route: '/reset',
            view: App.ResetView,

            token: Ember.ViewState.extend({
                route: '/:token_id',
                view: App.TokenView
            })
        })
    })
});

App.router = App.Router.create();
App.initialize(App.router);

1 Answer 1

1

You should have a look at the state of the art documentation about Router which is in-progress but available @ https://emberjs-staging-new.herokuapp.com/guides/outlets#toc_the-router

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Mike. That documentation looks much improved, I hadn't found it before.
I read that page and the details of the mentioned controllers, objects and templates are missing and I keep getting tripped up trying to stub something out for those. Do you have a full example somewhere?
Here is a full example courtesy of github.com/jbrown jsfiddle.net/justinbrown/C7LrM/10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.