Last active
August 29, 2015 13:55
-
-
Save IlanFrumer/8764935 to your computer and use it in GitHub Desktop.
ui router - trailing slash
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
app.config ($urlRouterProvider)-> | |
############################################################################################################################## | |
# https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-make-a-trailing-slash-optional-for-all-routes | |
############################################################################################################################## | |
$urlRouterProvider.rule ($injector, $location)-> | |
path = $location.path() | |
# Note: misnomer. This returns a query object, not a search string | |
search = $location.search() | |
# check to see if the path already ends in '/' | |
return if path[path.length - 1] is "/" | |
# If there was no search string / query params, return with a `/` | |
return path + "/" if Object.keys(search).length is 0 | |
# Otherwise build the search string and return a `/?` prefix | |
params = [] | |
angular.forEach search, (v, k) -> | |
params.push k + "=" + v | |
path + "/?" + params.join("&") | |
$urlRouterProvider.otherwise('/') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment