使用静默Backbone.js的变更网址为previous [英] Silently change url to previous using Backbone.js
问题描述
使用Backbone.js的,是有可能使路由器导航到它是从哪里来的页面?我想利用它来进行,我改变我的URL的弹出窗口时的情况,我希望去改回来,当我隐藏弹出。我不想简单地回去,因为我要保持precisely相同的位置,在我离开之前,我发现弹出的背景页
Using Backbone.js, is it possible to make the router navigate to the page where it came from? I'd like to use that for the case where I change my URL when a popup appears, and I want go change it back, when I hide the popup. I don't want to simply go back, because I want to keep the background page in precisely the same position as I left it before I showed the popup
推荐答案
我通过扩展Backbone.Router类和存储我的所有路由解决了这个问题,而导航:
I solved this problem by extending Backbone.Router class and storing all my routes while navigate:
class MyRouter extends Backbone.Router
constructor: (options) ->
@on "all", @storeRoute
@history = []
super options
storeRoute: ->
@history.push Backbone.history.fragment
previous: ->
if @history.length > 1
@navigate @history[@history.length-2], true
然后,当你不得不解雇你的模式,只需调用 MyRouter。previous()
方法,它会将您重定向回最后一个哈希
Then, when you have to dismiss your modal, simply call the MyRouter.previous()
method that it will redirect you back to the last "hash".
这篇关于使用静默Backbone.js的变更网址为previous的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!