Asp.net core project - changing root name leads to error finding module

This is the first time posting here. I am also new to Aurelia but like it.

I have a project that I was implementing JWT authentication and testing whether the JWT was in localstorage and subsequently switched the root to the authenticated root for the public one. Both have routes.

I Got it all working up to the point where I switch routes.

originally I had:

    aurelia.start().then(() => aurelia.setRoot(PLATFORM.moduleName('app/app/app')));

I changed it to:

    aurelia.start().then(function () {
    var auth = aurelia.container.get(AuthService);
    var root = auth.isAuthenticated() ? "app/app/app" : "public/public/public";
    aurelia.setRoot(root);

I get the error.

Uncaught (in promise) Error: Unable to find module with ID: public/public/public

I tried a number of work arounds. Finally I created a new asp.net CORE SPA Aurelia project from the EisenbergEffect/aspnetcore-aurelia-build-2017 github page.

Created it - it ran. It had as the root setting code in the boot.ts file:

    aurelia.start().then(() => aurelia.setRoot(PLATFORM.moduleName('app/components/app/app')));

Same code I and orginially as above.

Then changed the .setRoot so it had instead a string variable.

  aurelia.start().then(() => {
    var root: string  = 'app/components/app/app'
    aurelia.setRoot(PLATFORM.moduleName(root))
});

…and it cant find the module.

I asked this question on Stackoverflow and the silence was deafening.

I also note that anywhere I changeout a simple string for a string variable for .setRoot(someVariable) it fails with the same error.

This is a show stopper for me. Either I have done something stupid (Im new to this) or there is something else up.

If you want to have go at recreating this just download the project and run it in Visual Studio 2017. Then change out the simple string for a string variable in boot.ts.

Finally fixed this. I eventually changed my original code:

aurelia.start().then(function () {
var auth = aurelia.container.get(AuthService);
var root = auth.isAuthenticated() ? "app/app/app" : "public/public/public";
aurelia.setRoot(root);

to:

  aurelia.start().then(() => {
    var auth = aurelia.container.get(AuthService);
    let root: string = auth.isAuthenticated() ? PLATFORM.moduleName('app/app/app') : PLATFORM.moduleName('public/public/public');

    aurelia.setRoot(root, document.body)
});

and it now works. In the end it was my lack of programming skills however if anybody else has a problem they might try this for switching routes.

Not sure it was the document.body line that made a difference.

BTW Where did you hear about this setRoot idea for auth?