tryRoutingTo

fun tryRoutingTo(pathQueryAndFragment: String, updateHistoryMode: UpdateHistoryMode = UpdateHistoryMode.PUSH, openLinkStrategy: OpenLinkStrategy = OpenLinkStrategy.IN_PLACE, routeToErrorPageOnFail: Boolean = true): Boolean(source)

Attempt to navigate internally within this site, or return false if that's not possible (i.e. because the path is external or because the route isn't found).

By internally, I mean this method expects a route path only -- no https:// origin in other words. "/", "/about", "/help/contact", and "user/123" are valid examples.

You will generally call this method like so:

onClick { evt ->
if (ctx.router.tryRoutingTo(...)) {
evt.preventDefault()
}

That way, either the router handles the navigation or the browser does.

Note that this method will automatically prepend this site's BasePath if it is configured and if pathQueryAndFragment is absolute.

See also: navigateTo, which, if called, handles the external navigation for you.

Parameters

pathQueryAndFragment

The path to a page, including (optional) search params and hash, e.g. "/example/path?arg=1234#fragment". See also the standards documentation.

updateHistoryMode

How this new path should affect the history. See UpdateHistoryMode docs for more details. Note that this value will be ignored if pathQueryAndFragment refers to an external link.

routeToErrorPageOnFail

If true, and the input path fails to resolve to a known registered route, this method will then force the page to navigate to this site's error page (see also: setErrorPage). Otherwise, abort early, which can be useful if you have additional code you want to run that will do additional processing.