I have web site that has a path like: www.mytestsite.com. There really is nothing hosted at the site itself, it simply acts as the root of multiple web applications.
Each web application has a virtual path
: (e.g. /app1, /app2, etc.) So, to access app1, I would use: www.mytestsite.com/app1.
Each web application hosts an aurelia spa application – in fact, they all host the same application configured for different clients. So, when I build the app for production, I currently do the following:
- Update
webpack.config.js
to ensure thatindex.js
gets built with the correct path to load all the modules.
const baseUrl = '/app1/'
- Update my
app-config.ts
to ensure my app knows where to find the associated api for data
this.apiURL = "/app1/api/v1/" //api is hosted in same application
- Currently, in
app.ts
, I have my router configured like so:
config.options.pushState = true;
config.options.root = "/";
config.mapUnknownRoutes({ route: "unknown", redirect: "/"});
While this is a bit of a hassle, this all works – except, that once you hit the site, the browser url loses the virtual path of the application so a user can no longer tell which virtual app they are running.
IOW, you begin by accessing the app at: www.mytestsite.com/app1 and get the login page. Once you log in, the app sets the root to the ‘app’ module and the browser’s url changes to www.mytestsite.com/home. Notice the virtual path app1
is now missing. I was expecting to see www.mytestsite.com/app1/home.
I tried changing config.options.root="/app1/"
but that caused errors trying to load other modules.
Question
Is there a way to keep my virtual path in the url and still have my routing work such that once I login and am redirected, I would still see a url like: www.mytestsite.com/app1/home?
P.S. A few more details about my app that might play into this.
main.ts
await aurelia.start();
let usvc = aurelia.container.get(UserService);
if(!await usvc.isUserLoggedIn())
aurelia.setRoot(PLATFORM.moduleName('login/login'));
else
aurelia.setRoot(PLATFORM.moduleName('app'));
login.ts
public async loginButtonClick(){
...
//If successful login
this.router.navigate('/',{replace: true, trigger : false});
this.aurelia.setRoot(PLATFORM.moduleName("app");
}
routes.ts
export const routes = [
{
route: '',
redirect: 'home'
},
{
route: '/home',
nav: true,
name: 'home',
moduleId: PLATFORM.moduleName('./home/home','core'),
title: 'Home',
},
...
]