Last active
August 29, 2015 14:06
-
-
Save adambarthelson/60ad5a1c7a4ef6d8d893 to your computer and use it in GitHub Desktop.
HTML5 mode with Rails and UI-Router for handling hard GET's
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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); | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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; | |
}); | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
match "/*path" => redirect("/?redirectTo=%{path}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment