1

I'm using boilerplate and i have this routes where i have my viewmodels for every route.

controller.addRoutes({
            "editor" : new ContentEditor(context),
            "quiz_editor" : new QuizComponent(context)
        });

I'm looking how can i send variables from the viewmodel of editor to the viewmodel of quiz editor.

I saw an answer with this example:

controller.addRoutes({
'user/{id}' : new UserComponent(context),
});

But this is not working for me, because i don't want the variable going in a get. And if i do that, i need to use window.location for go to the url. So i don't like it, and i don't need it.

I'm looking for a better way to do it. Hope you can help me and save my life.

Thank you.

Rodrigo López
  • 227
  • 4
  • 17

1 Answers1

0

I would strongly recommend you to use URL parameters for this for several reasons: - It allow the use to bookmark the state of quiz_editor (e.g. send the link in Email) - Even if the user refreshes the page, quiz_editor will show the correct state - Search engine friendly

Buit if you dont want to use URLs for some strange reason, you can use the "moduleContext.notify" and "moduleContext.listen" methods to use event bus to communicate. But this would need listning the modules being pre initiated.

Another way if to use a mediator object (singleton) as a globally shared repository for different components to refer to.

Hasith
  • 1,749
  • 20
  • 26
  • See this related question too: http://stackoverflow.com/questions/13127153/sharing-datasources-between-components-on-a-boilerplatejs-app – Hasith May 16 '14 at 04:55