#possible solid router bug? navigate("../") doesn't go up when called from router root
23 messages · Page 1 of 1 (latest)
relative navigations are relative to the nearest route, not the url
in the case of the root component the nearest route is /
somewhat of a simple solution is to just take the current path and take everything until the last /
yeah that seems fine to me, or use substring
i think u could use useResolvedPath somehow to get a more reliable path
I think it's internal to solid-router
yeah
Maybe @brendonovich can provide an example, otherwise I would just go with the gpt answer
i'm not sure it'll solve the problem with the route config you provided, is that actually what your route config will look like?
like all hardcoded sibling routes rather than nesting or a wildcard parameter?
i ask bc for urls like that i usually do
<Route path="/a">
<Route path="/b">
<Route path="/c">
but maybe your usecase isn't conducive to nesting
Check this
<Router root={App}> <Route path="/a/b/c" component={PageC} /> <Route path="/a/b" component={PageB} /> <Route path="/a" component={PageA} /> <Route path="/" component={PageRoot} /> </Router>
is this just the same config but reversed?
yes
yeah bc u can generate the 'go up' route in the leaf route and then send it upwards to your root layout
the path splitting hack might just be good enough tbh
imma keep investingating tho, the router might have some extra utils
this code will help you
import { useLocation, useNavigate } from "@solidjs/router";
function NavBar() {
const navigate = useNavigate();
const location = useLocation();
function goUp() {
const pathSegments = location.pathname.split("/").filter(Boolean);
const parentPath = `/${pathSegments.slice(0, -1).join("/")}`;
navigate(parentPath);
}
return <div onClick={goUp}>go up!!</div>;
}```