Skip to content

Instantly share code, notes, and snippets.

@adambarthelson
Last active August 29, 2015 14:06
Show Gist options
  • Save adambarthelson/60ad5a1c7a4ef6d8d893 to your computer and use it in GitHub Desktop.
Save adambarthelson/60ad5a1c7a4ef6d8d893 to your computer and use it in GitHub Desktop.
HTML5 mode with Rails and UI-Router for handling hard GET's
.state('root.index', {
url: '/?redirectTo',
views: {
'content@':{
controller: 'MainCtrl',
templateUrl: 'templates/main.html'
}
},
authenticate: false,
onEnter: function(Redirect, $stateParams){
var redirect = new Redirect;
redirect.catch($stateParams);
}
})
(function(){
var app = angular.module('MyExport.redirects', ['ui.router']);
app.factory('Redirect', function($state) {
var Redirect = function() {
this.catch = function(params){
var path = _.reduce(params, function (paths, item) {
if (item != null){paths.push(item)};return paths;
}, [])[0];
if ( path != null ) {
var matchingState = _.where($state.get(), {url: '/'+path })[0];
if (matchingState != null) {
$state.go(matchingState)
}
}
}
};
return Redirect;
});
})();
match "/*path" => redirect("/?redirectTo=%{path}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment