router icon indicating copy to clipboard operation
router copied to clipboard

Route parameters have incorrect type

Open marcushellberg opened this issue 3 years ago • 2 comments

The Vaadin Router Docs says:

Named parameters are accessible by a string key, such as location.params.id or location.params['id'].

Issue

The type of the parameter returned by location.params.id is a string[], whereas the actual parameter is a string if you inspect it in the browser.

I'm unsure if this is a documentation or implementation issue

marcushellberg avatar Jun 02 '21 20:06 marcushellberg

The TS type is actually ParamValue which is defined as:

type ParamValue = string | string[];

There is support for "repeat params" so for a path of '/:a*' the location.params.a will be a string array e.g. when matching route /1/2/3 it will be ['1', '2', '3']. So that's why the type is essentially string | string[] and it seems correct to me.

Haprog avatar Jun 03 '21 06:06 Haprog

Sounds like more of a documentation issue then. Would be helpful to have 2 concrete examples of how to access a plain string parameter and an array

marcushellberg avatar Jun 03 '21 20:06 marcushellberg