0

I'm new to durandal. I just wondered if there was a way to pass in variables to the root view model aka the shell, either via querystring or any other way?

so main.js looks something like the below

define(['durandal/app'],  function (app) {
  app.configurePlugins({
    router: true
  });

  app.start().then(function () {
    app.setRoot('shell');
  });
});

Can you do something similar to what's written below in the shell.js file. I tried it but it doesn't work

function activate(variableIwantToPass) {
  doSomething(variableIwantToPass);
  configureRoutes(variableIwantToPass);
  return router.activate();
}

function configureRoutes(variableIwantToPass) {
  var specialRoute = 'bar';
  if(variableIwantToPass == 'foo') {
    specialRoute = foo;
  }
  var routes = [
    {
      route: '',
      moduleId: 'home'
    },
    {
      route: 'doThings/:specialRoute/',
      moduleId: 'orchestrator'
    }
  ];

  router.makeRelative({ moduleId: 'viewModels'}).map(routes); 
}

I can't make a call to a service to get the data in the shell as the information/variable I want is passed into the page that leads to the spa as a querystring parameter.

So, is it possible to pass something into the shell, or is there any other alternative to achieve what I want. Like creating a cookie to store this variable and reading it via javascript in shell.js?

Mayoweezy
  • 537
  • 1
  • 8
  • 21
  • "Can you so something like the below in the shell.js file" makes no sense to me, could you perhaps rephrase that? – Shelvacu Oct 27 '15 at 18:59

1 Answers1

0

In a production ENV, it's almost compulsory to do certain computation prior to shell. For instance take a look at Durandal.Auth on github and how authentication is handled and token info stored in session storage and is accessed in shell.