Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4838

Override existing catch-all wildcard route

$
0
0

@kleinfreund wrote:

The Ember application I’m working with has a catch-all wildcard route (i.e. *path). I cannot change this; however, I do want to have my own wildcard route. Since the existing route is applied after mine, it overrules my route. Thus, having my own catch-all wildcard route doesn’t work.

How can I register another catch-all wildcard route in this scenario or have my routes behave like one?

I’m able to catch all requests with the following router:

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' });
  });
}

The problem here is that this directs all multi-segment paths to the route main-route.sub-route. I tried to redirect the route, but I had no success with that. In particular, I need to redirect/transition to main-route in such a way that its beforeModel hook is executed.

The sub-route looks like this:

export default Discourse.Route.extend({
  afterModel(model) {
    this.transitionTo('main-route', model);
  }
});

This transitions to main-route fine.

However, it’s different than for requests targetting the main route directly. Especially, the properties for transition.intent are set differently. There is no transition.intent.url (presumably because I targetted a route name, not a URL) and the URL in the address bar only contains the path segment of the main route without the wildcard_path segment.


I realize that this is a hack/workaround that is unnecessarily complex. If I could remove the existing wildcard route, I wouldn’t need to look for such a solution.

Any pointers that could help me here?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4838

Trending Articles