Programmatical navigation with preact-iso is confusing due to the use of the useLocation hook which is limited by the rules of React hooks, rules that may not be intuitive.
From reading the issues, it seems that this is causing great confusion among users so I suggest a new API to change routes which would be more intuitive for users and would alleviate some of your support burden i.e.
#71
#54
#53
#97
I suggest a new function to navigate to a route that is not limited by the rules of React hooks.
import { pushRoute } from 'preact-iso';
function AnywhereInTheCode() {
// Anywhere in the code, not only in places where hooks can be used
pushRoute('/url');
}
Here are a few ideas of names for this function goTo, navigate, pushRoute.
From my reading of the code
|
function handleNav(state, action) { |
it seems that the
route function from
useLocation does not fundamentally need to be a hook, so we could move it to its own dedicated function.
Programmatical navigation with
preact-isois confusing due to the use of theuseLocationhook which is limited by the rules of React hooks, rules that may not be intuitive.From reading the issues, it seems that this is causing great confusion among users so I suggest a new API to change routes which would be more intuitive for users and would alleviate some of your support burden i.e.
#71
#54
#53
#97
I suggest a new function to navigate to a route that is not limited by the rules of React hooks.
Here are a few ideas of names for this function
goTo,navigate,pushRoute.From my reading of the code
preact-iso/src/router.js
Line 30 in 82cdde4
routefunction fromuseLocationdoes not fundamentally need to be a hook, so we could move it to its own dedicated function.