Skip to content

Instantly share code, notes, and snippets.

@pushrax
Created May 8, 2014 05:54
Show Gist options
  • Save pushrax/87e771551ddbc4740f67 to your computer and use it in GitHub Desktop.
Save pushrax/87e771551ddbc4740f67 to your computer and use it in GitHub Desktop.
replaceCurrentRoute: (params) ->
params = Batman.extend({}, params)
# ...
currentPageParams = @routableParams(params) # loads some more data (controller and action)
# ...
path = Shopify.get('dispatcher').pathFromParams(currentPageParams)
return unless path
currentPath = Shopify.get('navigator')?.pathFromLocation(window.location)
@_navigate(currentPath, path)
params
_navigate: (currentPath, newPath) ->
currentPathWithoutQuery = currentPath?.split('?')[0]
newPathWithoutQuery = newPath?.split('?')[0]
if currentPathWithoutQuery == newPathWithoutQuery
Shopify.get('navigator')?.replaceState {}, null, newPath
else
Shopify.get('navigator')?.pushState {}, null, newPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment