1

I am trying to configure Durandal child routing. I have a public section for witch the parent router is responsible:

//main router
return router.map(config.publicRoutes)
        .buildNavigationModel()
        .mapUnknownRoutes('account/login', '#login/')
        .activate();
//public routes
[{ route: 'login', title: 'Login', moduleId: 'account/login', nav: false, hash: '#login/' },
    { route: 'register', title: 'Register', moduleId: 'account/register', nav: false, hash: '#register/' },
    { route: 'reset-password', title: 'Reset password', moduleId: 'account/reset-password', nav: false, hash: '#reset-password/' },
    { route: 'private*details', moduleId: 'private/private-shell', title: 'Application', nav: true, hash: '#private/' }
];

Then a child router should be responsible for the private section. I am mapping the routes for the child router after the user has logged in. Depending on the user type (admin, user) I am activating the child router with the appropriate routes:

//initializing the router from the login view

 var promise = Q.all([private_shell.initRoutes(isAdmin || true)]);
 return promise.then(navigate("#private/silos"));



// child router in private-shell

var privateRouter = router.createChildRouter();
var routes = [];

//method to initialize the proper routes after login
var initRoutes = function (isAdmin) {
    privateRouter.reset().makeRelative({
        moduleId: 'viewmodels/private/',
        fromParent: true
    });
    console.log(privateRouter);
    return privateRouter.map(isAdmin ? config.adminRoutes : config.userRoutes).buildNavigationModel();
};

The first time when the router is initialized all works fine but if I return to the main router(login view) and another login is performed the child router adds the relative moduleId twice.

After the first login the routes have the moduleId ´viewmodels/private/route´, which is the right one, but second time the login initializes the child router the routes have the moduleId ´viewmodels/private/viewmodels/private/route´.

GET http://localhost:7777/App/viewmodels/private/viewmodels/private/silos.js 404 (Not Found)

When it should be:

GET http://localhost:7777/App/viewmodels/private/silos.js

I wasn't able to identify what might cause this. Any help?

Razvan
  • 3,017
  • 1
  • 26
  • 35

1 Answers1

0

Can you try specifying the parent route in a route property on the makeRelative settings object? Perhaps also try making the reset call explicit. Like this:

privateRouter.reset();
privateRouter.makeRelative({
    moduleId: 'viewmodels/private/',
    fromParent: true,
    route: 'viewmodels/private'
});
Alexander Preston
  • 1,665
  • 11
  • 15
  • 2
    The route names are configured properly. Their modules are the problem. The moduleId from the router settings (when I call `childRouter.makeRelative`) to the routes moduleId's every time I initialize the childRouter. `GET http://localhost:7777/App/viewmodels/private/viewmodels/private/silos.js 404 (Not Found)` – Razvan Mar 07 '14 at 09:18