Remember history to support browser back with @navigate used in redirects.

This commit is contained in:
Martin Edenhofer 2015-09-02 20:05:48 +02:00
parent f9d027d180
commit 37f1a765e4
4 changed files with 19 additions and 9 deletions

View file

@ -29,14 +29,16 @@ class App.Controller extends Spine.Controller
ajaxId = App.Ajax.request(data) ajaxId = App.Ajax.request(data)
@ajaxCalls.push ajaxId @ajaxCalls.push ajaxId
navigate: (location, hide_current_location_from_history = false) -> navigate: (location, hideCurrentLocationFromHistory = false) ->
@log 'notice', "navigate to '#{location}'" @log 'notice', "navigate to '#{location}', hide from history '#{hideCurrentLocationFromHistory}'"
# hide current location from browser history, allow to use back button in browser # hide current location from browser history, allow to use back button in browser
if hide_current_location_from_history if hideCurrentLocationFromHistory
@log 'debug', "ignore new location from browser histroy '#{location}'"
if window.history if window.history
window.history.replaceState(null, null, location) history = App.Config.get('History')
oldLocation = history[history.length-2]
if oldLocation
window.history.replaceState(null, null, oldLocation)
super location super location
bind: (event, callback) => bind: (event, callback) =>

View file

@ -1,3 +1,4 @@
App.Config.set('History', [])
App.Config.set('User', { App.Config.set('User', {
prio: 1000, prio: 1000,
parent: '', parent: '',

View file

@ -1,4 +1,4 @@
class Index extends App.Controller class DefaultRouter extends App.Controller
constructor: -> constructor: ->
super super
@ -28,5 +28,5 @@ class Index extends App.Controller
@navigate '#dashboard', true @navigate '#dashboard', true
App.Config.set( '', Index, 'Routes' ) App.Config.set( '', DefaultRouter, 'Routes' )
App.Config.set( '/', Index, 'Routes' ) App.Config.set( '/', DefaultRouter, 'Routes' )

View file

@ -87,6 +87,13 @@ class App.Content extends App.ControllerWidgetPermanent
params: params_only, params: params_only,
) )
# remember history
# needed to mute "redirect" url to support browser back
history = App.Config.get('History')
if history[10]
history.pop()
history.push window.location.hash
# execute controller # execute controller
controller = (params) => controller = (params) =>
params.el = @el params.el = @el