solidjs / solid-router

A universal router for Solid inspired by Ember and React Router
MIT License
1.1k stars 137 forks source link

Why not just export useRouter and useRoute? #408

Closed zxdstyle closed 2 months ago

zxdstyle commented 2 months ago

Describe the bug

I have no way to get the info assigned to the current route when it was defined.For example, I want to get the value of the following route definition checkAuth

const routes: RouteDefinition[] = [
    {
        path: '/home',
        component: lazy(() => import('@/views/home')),
        info: {
            checkAuth: true,
        },
    },
]

Your Example Website or App

empty

Steps to Reproduce the Bug or Issue

empty

Expected behavior

empty

Screenshots or Videos

No response

Platform

Additional context

No response

ryansolid commented 2 months ago

Yeah we should. I'm surprised a bit we haven't.

EDIT: On further inspection there is a lot of internals here. We probably should just make a hook for this. Because you often don't want just the one info but the whole matched route. So you kind of want to use useMatch I think or some variation of that. Let me try some stuff.

It looks like useMatch only grabs the immediate one.. hmm.. we might need something here.

ryansolid commented 2 months ago

I've updated the readme with an example using useCurrentMatches