Skip to content

Commit

Permalink
Use RegExp to handle optional rest and query segments
Browse files Browse the repository at this point in the history
Use RegExp instead of pattern for app route, because Crossroads.js
extracts the query string as part of the rest segment. This is because
it does not support having both segments as optional.
See: millermedeiros/crossroads.js#130
  • Loading branch information
guillegr123 committed Jun 17, 2022
1 parent 23901b9 commit 4e0e812
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/js/lib/monster.routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,17 @@ define(function(require) {
},

addDefaultRoutes: function() {
this.add('apps/{appName}:?query:', function(appName, query) {
this.add(/^apps\/([^/?]+)(?:\/[^?]*)?(\??.*)?$/, function(appName, query) {
// not logged in, do nothing to preserve potentially valid route to load after successful login
if (!monster.util.isLoggedIn()) {
return;
}

// Do not reload app if it is already loaded (just the rest segment or the query has changed)
if (monster.apps.getActiveApp() === appName) {
return;
}

var availableApps = monster.util.listAppStoreMetadata('user');

// try loading the requested app
Expand Down

0 comments on commit 4e0e812

Please sign in to comment.