[英]Ember.JS - store a route, then transition to it later
I'm trying to figure out a good way to temporarily store a reference to the current route so that I can transition back to it later. 我正在尝试找到一种临时存储对当前路线的引用的好方法,以便以后可以转换回它。
I know that from within a route I can do: 我知道从路由中我可以做到:
r = @get("routeName")
and then later: 然后再:
@transitionTo ( r )
But that doesn't include dynamic segments. 但这不包括动态细分。 Is there anyway to do this easily? 反正有容易做到这一点吗?
How about: 怎么样:
completeRoute = @get("routeName")
args = [completeRoute]
tempRoute = ''
completeRoute.split('.').forEach (route)=>
tempRoute += route
args.push(@modelFor(tempRoute)) if @modelFor(tempRoute)
tempRoute += '.'
and then 接着
@transitionTo.apply(@, args)
I haven't tried this, but I guess something like that might work. 我没有尝试过,但是我猜类似的东西可能有用。
One way I solved this in my app was to just use window.location.pathname
instead of relying on the routeName
variable. 我在应用程序中解决此问题的一种方法是仅使用window.location.pathname
而不是依赖于routeName
变量。 I was serializing to localStorage
, so it was easier to just store the entire path instead of a bunch of objects. 我正在序列化到localStorage
,因此只存储整个路径而不是一堆对象会更容易。
@pathname = window.location.pathname
and then, later: 然后,稍后:
@transitionTo(@pathname)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.