System.perspective.navigate with view parameter

In the context of a multi-page application i'm trying to perfect a strategy for navigating from a page to the others.
I'm finding it difficult because there is not an obvious solution and combining the different approaches is not always viable because of behaviours that i didn't expect.
I found different problems but it would be too much material for a single question, so I decided to dedicate a question for each single problem.
This is dedicated to the navigate via view parameter that doesn't work with the browser's refresh button.

I'm talking of the code:

system.perspective.navigate(view ='folder/myView')

It seems to me that it should be kept apart from the others (page and url) because it's completely different.
When system.perspective.navigate is called with page or url parameter it causes the browser to change its address and reload from the new URL; in this case there should be a page configuration that 'connects' the url to the view.

Instead, when the parameter 'view' is used, the browser is not involved in the operation; it's a server-only functionality in which the specified view is rendered in the current URL. As a consequence, this way does not require a page configuration to 'connect' (or 'publish') the view to an url.

What is the use case for this navigation strategy? I thought of this: I have a page that can show a certain document but requires the user to look up in a list which one they want to open.

I can publish a single URL and just switch between the document view and the lookup (or index) view as needed.

Unfortunately, after implementing this solution i discovered that hitting the refresh button of the browser, the view goes back to the initial view.

How to reproduce the problem

I created a main view and a secondary view; only the main view has an url associated in Page configuration.

image

The main view contains only a button. The button's onActionPerformed navigates to "SecondaryView" using the view parameter:

Additionaly i passed to the view a parameter with the current timestamp to see if it gets refreshed correctly.

The secondary view has the parameter myViewParam and shows it in a bound label.

Now in the browser we see this:

When you click the button the server renders the "SecondaryView" to the same url:

The problem: if at this point you click refresh in the browser it goes back to the MainView.

I couldn't find any reference to this behavior in the docs and if in some cases it may be beneficial to a certain specific applications, in general it seems to introduce a degree of instability at the interface level that has to be fixed with different workarounds. (For example, I tried to call system.perspective.navigate from the onStartup event of the view if certain conditions are not met. It works but again it does not 'seem right').

Most of all it seems like this is not the preferred navigation strategy in perspective.

Any idea about this? Should be avoided? Has some specific use cases that I couldn't came up with? Is there a way to fix it?

The docs talk about this behavior if using the view parameter.

Before I start breaking down your question, I'd like to clarify something that a lot of people get hung up on when thinking about how Perspective behaves in the browser.

Many users are used to using multi-page websites in a browser. Multi-page in this context means the website has multiple .html files in use, and navigating to a different "page" means modifying the URL in some manner, the website looking up or retrieving some new .html file, and rendering that new layout. Perspective, on the other hand, is a Single-page application/website. Once you land on a Perspective page and have loaded all of the necessary resources there is no further HTTP traffic - everything is done via websocket traffic (data pipeline). That the URL of the browser changes is just some hand-wavy magic we do to make it clear to a user what Page Configuration is in use.

Not quite. This is true for url because Perspective will actually make a new HTTP GET request when navigating via URL. When page is used, we update the URL bar of the browser, but no HTTP call is made. We update the internal browser listings well so that back/forward navigation works as expected. Again, no HTTP call is made, we're using JavaScript to re-render your single Page/tab to display the View saved within the Page Configuration of this mounted path.

I have seen thousands of applications for our behaviors that I never would have thought of, so I'm sure someone somewhere uses this strategy extensively. Why or how I could not tell you.

I would not call this a problem/bug. It's documented to work exactly as it does. While it's unfortunate it does not meet your expectations for what it should do, that does not make it broken or a bug.

It is absolutely NOT the preferred or recommended navigation strategy within Perspective. Almost all navigation should be using page. Even url should likely only be when switching between projects or directing a user to an external website. Some users prefer url when passing parameters.

4 Likes