Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we route from a component in ember js?

Tags:

ember.js

I have a component which has a button with an action like {{action 'create'}} and inside the action create i wrote like this.transitionTo('page.new'); But i am getting an exception like Cannot read property 'enter' of undefined can anyone answer please?Just want to know is that possible to route from a component?

like image 524
Joseph Avatar asked Mar 27 '14 09:03

Joseph


People also ask

What is route in Ember js?

An Ember route is built with three parts: An entry in the Ember router ( /app/router. js ), which maps between our route name and a specific URI. A route handler file, which sets up what should happen when that route is loaded (app/routes/about.

How do you pass a value to a component in Ember?

To set the component up to receive parameters this way, you need to set the positionalParams attribute in your component class. import Component from '@ember/component'; export default Component. extend({}).

What is component in Ember js?

Ember components are used to turn markup text and styles into reusable content. Components consist of two parts: a JavaScript component file that defines behavior, and its accompanying Handlebars template that defines the markup for the component's UI. Components must have at least one dash in their name.

What is index route Ember?

Index Routes. At every level of nesting (including the top level), Ember automatically provides a route for the / path named index . To see when a new level of nesting occurs, check the router, whenever you see a function , that's a new level. For example, if you write a simple router like this: app/router.js Router.


2 Answers

The way to do that is to use this.sendAction() from your component and bubble it up to the router. The router can then call this.transitionTo().

The way link-to does it is by injecting routing _routing: inject.service('-routing'),

https://github.com/emberjs/ember.js/blob/v2.1.0/packages/ember-routing-views/lib/components/link-to.js#L530

like image 195
coulix Avatar answered Sep 21 '22 17:09

coulix


Ember.Component is extended from Ember.View and you cant use this.transitionTo in a view. It can be done only through a controller/router.

If you want a transition inside the component on clicking, you could use the link-to helper, but if you still want to be able to handle that action, read: http://emberjs.com/guides/components/handling-user-interaction-with-actions/ and the guide after it.

like image 31
rahulcs Avatar answered Sep 21 '22 17:09

rahulcs