Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vaadin router should follow standard navigation if it cannot find a route #716

Open
pietrorea opened this issue Jan 19, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@pietrorea
Copy link

pietrorea commented Jan 19, 2022

I'm working in a situation where there are multiple frontend single page apps (e.g. auth, admin, app) and I'm having to link from one to another pretty often but it's very cumbersome. With the existing setup...

i) I can't set up a default route (e.g. { path: '(.*)', component: 'not-found-page'}) because if I try to link to another SPA or any other external resource, it will get caught the not-found-page component and that's not what I want.
ii) I can't count on Vaadin to fall back on standard navigation if there isn't a route that matches. I get a Error: [Vaadin.Router] Page not found.

Ideally, I don't want to keep track of which is an internal (internal to this SPA) link and which isn't and do something different for each link. I just want to configure the router and use it for all my routing needs. The best solution I have so far is a default route with a custom action:

  { path: '(.*)', action: (context, commands) => {
    window.location.assign(context.pathname);
    commands.prevent();
  }}

I don't 100% like this solution because I have to remember to do this in all my frontend SPAs. I would prefer if this behavior were a RouterOption I could pass when first setting up the router.

@platosha platosha added the enhancement New feature or request label Mar 14, 2022
@platosha
Copy link
Contributor

Hi @pietrorea, thanks for filing this. Good idea for an enhancement, I think.

Ideally, the router’s path matching was sync, we could avoid event.preventDefault() for the click event if the path matching did not find a good route, so that the browser handling continues naturally handling the link click with standard navigation (not possible today as the path matching is async).

Sounds good to make it an opt-in behaviour also.

Related tip, if each Vaadin router in your case is only handling a specific path-prefixed scope, consider using the baseUrl option. This prevents Vaadin router from handling link clicks outside the path-prefixed scope (e. g., for <a href="/admin">Admin app</a> link it would use standard navigation if the router’s baseUrl is set to /app).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants