Conrad Vanlandingham
Conrad Vanlandingham

Reputation: 1000

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?

Upvotes: 1

Views: 286

Answers (2)

mjackson
mjackson

Reputation: 664

One way I solved this in my app was to just use window.location.pathname instead of relying on the routeName variable. I was serializing to localStorage, so it was easier to just store the entire path instead of a bunch of objects.

@pathname = window.location.pathname

and then, later:

@transitionTo(@pathname)

Upvotes: 0

Teddy Zeenny
Teddy Zeenny

Reputation: 3971

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.

Upvotes: 2

Related Questions