Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining routes using arrow functions doesn't work #1597

Open
Kamaropoulos opened this issue Nov 18, 2017 · 1 comment
Open

Defining routes using arrow functions doesn't work #1597

Kamaropoulos opened this issue Nov 18, 2017 · 1 comment

Comments

@Kamaropoulos
Copy link

Kamaropoulos commented Nov 18, 2017

Defining a route using the following code:

Router.route('/', () => {
    this.render('myTemplate');
});

will print an error in the console:

Route dispatch never rendered. Did you forget to call this.next() in an onBeforeAction?

while the same code but with a regular function callback will work as expected:

Router.route('/', function() {
    this.render('myTemplate');
});

I know that the default way to define routes is with regular functions but shouldn't this theoretically work?

@Kamaropoulos Kamaropoulos changed the title Defining a route using arrow functions doesn't work Defining routes using arrow functions doesn't work Nov 18, 2017
@zimme
Copy link
Contributor

zimme commented Apr 27, 2018

No, because render is attached to this which is bound when using an arrow function. i.e. an arrow function won't get the special this context that iron-router gives to the route handlers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants