[Feature]: Number support for `to`

Posted 1 month ago

[Feature]: Number support for `to` #8123

What is the new or updated feature that you are suggesting?

It would be a really simply and nice touch if Link, NavLink and Redirect would support to as number for history.go().

<NavLink to={-1}>Go back</NavLink>
<NavLink to={-1}>X</NavLink>

Why should this feature be included?

This would a handy in many cases, eg. close button of overlays. It's saving some time compared to custom implementing this onClick and loading the history obj always.

Created 1 month ago

Since we cannot always know what URL is at a given entry in the history stack because of browser security concerns (it's just not available to use) we would not be able to compute an accurate href value for the underlying <a> if all we have is a number. This would break accessibility for things like right click to open in a separate tab, etc. So unfortunately we can't do this.