Discourse has a catch-all route using a wildcard path.
app/assets/javascripts/discourse/mapping-router.js.es6
:
this.route("unknown", { path: "*path" });
As far as I can tell, this stops plugins from having the same catch-all rule because Discourse’s rule is executed later, thus taking precedence. Atleast when commenting out Discourse’s rule temporarily, the following works as expected:
plugins/plugin/assets/javascripts/discourse/plugin-name-route-map.js.es6
:
this.route('main-route', { path: '*wildcard' });
Is there a way to have a catch-all route for a plugin with only one route?
Attempt 1:
Nested routes.
plugins/plugin/assets/javascripts/discourse/plugin-name-route-map.js.es6
:
export default function () {
// Matches single-segment paths.
this.route('main-route', { path: '/:path' }, function () {
// Optionally, matches subsequent segments.
this.route('sub-route', { path: '*wildcard_path' });
});
}
This has the major issue that requests matching /:path
will use the route main-route.index
whereas requests matching /:path/*wildcard
will use the route main-route.sub-route
. I need all requests to go through main-route.index
.
Attempt 2:
Multiple paths, same routes.
(This seems to have worked in older Ember version, but does no longer.)
plugins/plugin/assets/javascripts/discourse/plugin-name-route-map.js.es6
:
export default function () {
// Matches single-segment paths.
this.route('main-route', { path: '/:path' });
// Doesn’t match multi-segment paths.
this.route('main-route', { path: '/:path/*wildcard_path' });
}
or
plugins/plugin/assets/javascripts/discourse/plugin-name-route-map.js.es6
:
export default function () {
// Matches multi-segment paths.
this.route('main-route', { path: '/:path/*wildcard_path' });
// Doesn’t match single-segment paths.
this.route('main-route', { path: '/:path' });
}