Saturday 15 March 2014

angularjs - Redirect after login to backbone route with rails -



angularjs - Redirect after login to backbone route with rails -

i attempting provide users mutual functionality, redirecting them after login requested url behind secure path. example, user clicks link in email triggered via notification in system, attempts go to: https://mysite.com/secure/notifications/1 user not logged in kicked https://mysite.com/login after login should brought not home page, requested url.

i familar technique store attempted url in session before redirecting login page. issue if url contains backbone router after core url, ie https://mysite.com/secure/notifications/1#details

the #details part of url not sent server seems, typically inner page jumping. wondering how web developers dealing js mvc frameworks backbone, angular, , other emerging? trick? way have # pass server in http specification?

any ideas appreciated, give thanks you.

the easiest solution problem, if don't need back upwards behaviour older browsers, enable pushstate in backbone router don't utilize # routes:

backbone.history.state({pushstate: true});

edit:

the other potential solution, though bit messy, url tomfoolery figure out should after hash , navigate route.

for example, let's want navigate to:

http://webapp.com/abc/#page1 'page1' fragment makes backbone route.

if instead send user http://webapp.com/abc/page1. can observe whether browser has pushstate. if not, can replace after 'root' hash. here illustration code might on right track supporting both sets of browsers:

class="snippet-code-js lang-js prettyprint-override"> var _defaults = { pushstate: modernizr.history, silent: true, root: '/' }; var start = function(options) { // start routing either pushstate or without options = _.extend(_.clone(this._defaults), options); backbone.history.start(options); if (options.pushstate) { backbone.history.loadurl(backbone.history.getfragment()); return; } this.degradetononhistoryurl(); }; /** * fragment urls, check if actual request root i.e '/', * if is, can go on , backbone magic * if isn't redirect root route fragment * foo.com/bar/1 -> foo.com/#bar/1 */ degradetononhistoryurl = function() { var pathname = window.location.pathname; // if root '/', length one. if root 'foo', length 5 (/foo/) var rootlength = _getroot().length; var isrootrequest = pathname.length === rootlength; if (!isrootrequest) { var route = pathname.substr(rootlength); window.location.href = _getroot() + '#' + route + window.location.search; return; } backbone.history.loadurl(backbone.history.getfragment()); }, /** * effective root of app. it's '/', if set 'foo', want * homecoming '/foo/' can more determine if root request or not. * @returns {string} effective root */ _getroot = function() { if (backbone.history.options.root === '/') { homecoming '/'; } homecoming '/' + backbone.history.options.root + '/'; },

the trick here making pushstate url canonical urls , sending users ones. 1 time browser adoption increases, should theoretically easy cutting of crap out without having update of links.

ruby-on-rails angularjs backbone.js

No comments:

Post a Comment