Router with "stack"-functionality


I know this topic may be a bit “controversial”, but I was wondering if the router in vNext will support some kind of stack functionality. As far as I know the current implementation doesn’t have that kind of feature. If I’m wrong and there is a way of doing this, please let me know :smile:

Let me explain what I mean:
When navigating from one route to another there should be some kind of option to decide whether the current view will be kept in background and the new view will “overlay” the old one or whether the stack will be cleaned before.

To be more specific:
Imagine you are in a search-view where you entered multiple search criterias. You see multiple search results and click one and so navigate to the detail-view of this record. Now you find out that you’ve clicked to wrong one. You navigate back to the search-view. Now you have to enter the search criteria once again … In this case it would be great if the router just removes the detail-view and shows the search-view, which was kept in background, again.

To prevent that the stack will increase infinite there could be a max stack size …


1 Like

Did you look into strategy? Perhaps there is a way to re-use and not re-create a view when routed back to it.

1 Like

Hello @khuongduybui,

thanks for your answer. As far as I understand the router activation strategy, it’s not quite what I want.

I forgot to write in the ticket that it should also be possible to open a view multiple times (although of course max. one view is currently visible). If the user clicks back in the browser, this view should be disposed. Or if a corresponding navigation is executed, which resets the stack, then all views should be disposed.

1 Like

I mean you can use the di and make it a singleton?

1 Like

@stefan I’m sure what you’re describing is how the router currently works. The stack you’re describing is the browser history and the router already uses this.

Maybe I’m not fully understanding the problem?

1 Like

Looks like my explanation wasn’t really good, sorry.

I have created a small example:

  1. enter “A” in the input and click on a link
  2. enter “B” in the input and click on a link
  3. enter “C” in the input and click on a link

Now click Back on the browser. C" is displayed.
Click Back again. Now “B” is displayed, …

It is always the same view, but different instances of it.

I hope it’s clearer now what I meant.
Does the current or new router support such a function?


When navigating away from a view/view-model, its current state is destroyed. Instead of destroying it, @stefan would like the ability to save it on a stack so the user can navigate back and see the same view/view-model state.


@stefan The vCurrent router doesn’t have quite what you want although this PR would help make it possible.

For the vNext router, however, there are plans to support “stateful components” from early on. The stacking behavior you describe would be a setting for how the component cache would behave.

You can find a (still slightly buggy) demo here – instructions are in blue on the first page – and some other vNext router demos here.