router icon indicating copy to clipboard operation
router copied to clipboard

Router.go should find a route based on its defined path relative to the base href

Open nweldev opened this issue 2 years ago • 0 comments

Description of the bug

When using a <base href> element, router.baseURL correctly retrieves the right value. However, when trying to call Router.go(relativePath), no route is found. Calling Router.go(document.querySelector('base')?.href + relativePath) does work as a workaround.

Minimal reproducible example

See https://github.com/blindnet-io/privacy-components-web/pull/84

  • The related open source demo project can be found and run from here: https://github.com/blindnet-io/privacy-components-web/tree/develop/demos/devkit-simple-tutorial
  • Router configuration: https://github.com/blindnet-io/privacy-components-web/blob/ad9649ab9f5c254a35a38375dbe1194be39a7ba0/demos/devkit-simple-tutorial/src/DevkitSimpleTutorial.js#L45-L77
  • Using Router.go with the workaround: https://github.com/blindnet-io/privacy-components-web/blob/ad9649ab9f5c254a35a38375dbe1194be39a7ba0/demos/devkit-simple-tutorial/src/views/BackOffice.js#L10-L18

Expected behaviour

When defining the following route:

{ path: '/myroute', component: 'app-my-component' }

And a base href:

<base href="/my/subdir/`>

Calling Router.go('/myroute') should find and load the associated route.

Actual behavior

Only Router.go('/my/subdir/myroute') works (adding the base href manually).

Versions:

  • Vaadin / Hilla version: @vaadin/[email protected]
  • Node version: v16.14.0
  • Java version: None

nweldev avatar Sep 02 '22 11:09 nweldev