Open
Description
What problem does this feature solve?
Currently if you pass a hash id with unescaped CSS special characters /[!"#$%&'()*+,\-./:;<=>?@[\\]^{|}~]/
to a scrollBehavior selector, execution will fail:
'XXX' is not a valid selector
Because of this url-styled hashes (e.g. "#one/two"
or "#main/secondary"
), both valid ids in HTML5, cannot be passed directly from the to.hash
or from.hash
parameters.
This is because behind the scenes document.querySelector
, which relies on CSS character compliance, is used in all but a very small number of circumstances (i.e. /^#\d/
). This feature proposes broadening the use case for document.getElementById
to all selectors that have the appearance of an id, specifically ungrouped selectors starting with a hash (i.e. /^#[^, ]+$/
)
What does the proposed API look like?
API doesn't change, except the following would work:
scrollBehavior(to, from, savedPosition) {
return {
selector: to.hash,
}
}
// where:
window.location = '/one/two#three/four';