16

If I want to have a URL on an Ember.js website called example1.com that forwards to a URL on example2.com, how would I do that. Can I create a route of example1.com that will perform the forward to example2.com - maybe in the beforeModel hook?

Chris
  • 824
  • 1
  • 7
  • 26
  • Is there a reason not to use a simple href? What are your limitations that make this ember specific? – Jake Haller-Roby Mar 20 '14 at 19:01
  • It doesn't need to be Ember-specific, but it's not a link. If I enter a URL in the browser address bar for http://example1.com/page1 (which happens to be an Ember.js app), it needs to forward automatically to http://example2.com/page2. – Chris Mar 20 '14 at 19:04

2 Answers2

17

Just use a regular <a>:

<a href="example2.com">Route to Example 2</a>

If you want to have it forward if the user types in the URL directly into the address bar, you will need to do that redirect in your server. That doesn't have anything to do with Ember though.

Alternatively you could just use

App.YourRoute = Ember.Route.extend({
  redirect: function() {
     window.location.replace("http://stackoverflow.com");
  }
});

The beforeModel (or any other) hook should also work.

chopper
  • 6,649
  • 7
  • 36
  • 53
12

In any hook, use:

window.location.replace("example2.com");
Panagiotis Panagi
  • 9,927
  • 7
  • 55
  • 103
Jake Haller-Roby
  • 6,335
  • 1
  • 18
  • 31