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?
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.
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({}).
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With