Francisco Ortiz
Francisco Ortiz

Reputation: 548

EmberJS: Pass data between routes

What do you recommend to pass a message between routes? What I would like to get is:

I have thought on creating a new path for the login route (signup_confirmation). There, if the path is signup_confirmation, it will display the message.

Thoughts?

Thank you in advance!

Upvotes: 2

Views: 2314

Answers (2)

XYZ
XYZ

Reputation: 27387

Base on your requirement, the service is a great place to share data between different app state.

An Ember.Service is an Ember object that lives for the duration of the application, and can be made available in different parts of your application.

Services are useful for features that require shared state or persistent connections. Example uses of services might include:

  • User/session authentication.
  • Geolocation.
  • WebSockets.
  • Server-sent events or notifications.
  • Server-backed API calls that may not fit Ember Data.
  • Third-party APIs.
  • Logging.

https://guides.emberjs.com/v2.11.0/applications/services/

Upvotes: 2

Gennady Dogaev
Gennady Dogaev

Reputation: 5991

Your options:

  1. Add signupMessage property to login controller, then in signup controller inject login controller and set a value of signupMessage after registration. Then you can display it in login template (don't forgret to clear this property when user goes away from login route, deactivate event of route should help with this).
  2. Create a service, memoryStorage to store data that can be accessed from different places. In signup controller you can then set a message and from login controller get it and display (and remove from memoryStorage, of course).
  3. Use flash messages, which will be displayed for few seconds somewhere on the page, no matter what route is active now. ember-cli-flash is a good addon for this solution.

Upvotes: 3

Related Questions