0

I have model object:

module.exports = {
 redirectTo: function(params, callback) {
  callback(null, 'home/redirect_to');
 }
}

Can I redirect user without loading page?

It will depend on variables, so redirecting not always needed. The only thing I need now is redirecting from server-side.

Emin Mastizada
  • 1,375
  • 2
  • 15
  • 30

2 Answers2

0

Server side redirection can be done by simply replying HTTP 302 to client.

If what you are asking is "How to go around server side redirection so that your Backbone callback can still be triggered?", then my solution will be following:

For example, when an user type a url http://yousite.com/blog/someid on his browser, and you want to use Backbone callback to handle his request. Then you can let your server return:

<script> window.location="http://yoursite.com#blog/someid"</script>

Note we replace a / into #.

Or, you can let your server return (fragment allowed in Location):

HTTP/1.1 302 Found
Location: http://yoursite.com#blog/someid

Then your Backbone callback will be triggered.

Ming
  • 4,110
  • 1
  • 29
  • 33
  • I will detect rather redirect to an url or not. If yes, I need to return 302 (or 301) redirect to user. So, How I can return 302 redirection in controller? – Emin Mastizada Apr 11 '14 at 21:34
  • @EminMastizada So you are asking how to return 302 in server side controller (`NodeJS`)? Here's a [solution](http://stackoverflow.com/questions/4062260/nodejs-redirect-url) – Ming Apr 11 '14 at 21:47
  • thanks for all, I tried this.redirectTo() and it worked. – Emin Mastizada Apr 11 '14 at 22:02
0

It can be done using this.redirectTo(url)

Emin Mastizada
  • 1,375
  • 2
  • 15
  • 30