Search code examples
ember.jsember-router

From the router, how can I route to a completely different parent route in EmberJS


Suppose I have the following URL.

www.mywebsite.com/foo/abc/def

And in my router, it might look something like this:

this.route('foo',  function() {
    this.route('fooo');
    this.route('foooo');
    this.route('abc', function() {
      this.route('def');
      this.route('def, {path: 'def.html'});
       // Some other routes
    }
    // Some other routes
}
// Some other Routes

So what happens now if I want my foo/abc/def to redirect to somewhere COMPLETELY different. Like, for example, bar/uvw/xyz. How can I redirect to there? Is there a way to do it from a the router? I could write transition logic within the /foo/abc/def route but that seems a bit messy.

The reason I need to do this is because I'm transitioning one of our companies websites to a new Ember site. And we want to change the routes to some of our products but make sure people who have saved links to those webpages won't get dead-links.


Solution

  • You can't do that from the router. You need to place your redirects inside JavaScript code of your Route.

    As @locks suggested it might be a good place for you to start with reading Redirecting guides.