# Plugin com mapa de rota curinga universal

**URL:** <https://meta.discourse.org/t/plugin-with-catch-all-wildcard-route-map/100348>\
**Category:** Development\
**Created:** [24 Outubro , 2018 12:12 UTC](https://meta.discourse.org/t/plugin-with-catch-all-wildcard-route-map/100348 "2018-10-24T12:12:09Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![kleinfreund](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@kleinfreund](https://meta.discourse.org/u/kleinfreund)\
**Post date:** [24 Outubro , 2018 12:12 UTC](https://meta.discourse.org/t/plugin-with-catch-all-wildcard-route-map/100348/1 "2018-10-24T12:12:09Z")

</div>

Discourse has a catch-all route using a wildcard path.

**`app/assets/javascripts/discourse/mapping-router.js.es6`** :

```js
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`** :

```js
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`** :
> 
> ```js
> 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`** :
> 
> ```js
> 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`** :
> 
> ```js
> 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' });
> }
> 
> ```

---

_[View the full topic](https://meta.discourse.org/t/plugin-with-catch-all-wildcard-route-map/100348)._
