Casey Gov
Casey Gov

Reputation: 21

Ember redirect old routes

I have an Ember app where I am renaming a few routes. I am concerned users may have the old routes bookmarked. Where is the best place to handle redirects from the old route to the new one?

Upvotes: 1

Views: 272

Answers (1)

Chris de Almeida
Chris de Almeida

Reputation: 458

What you probably want is replaceWith: replaceWith documentation

you would use it like this:

// app/router.js
Router.map(function() {
  this.route('old-route');
  this.route('new-route');
});
// app/routes/old-route.js
export default Route.extend({
  beforeModel() {
    this.replaceWith('new-route');
  }
});

Now, if what you wanted to do is KEEP the original route (which it doesn't sound like you want to do but I mention it for completeness) is use ember-route-alias

further reading: Ember guide on redirecting

Upvotes: 2

Related Questions