solidjs / solid-router

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

<A> Component causes incorrect error message when used outside of a <Route /> #389

Closed pixelprogrammer closed 4 months ago

pixelprogrammer commented 5 months ago

Describe the bug

When using the <A> component outside the <Route/> you get the following error message:

Uncaught Error: Make sure your app is wrapped in a <Router />

By simply moving the <A> component inside a route component. This error message goes away. It feels like the wrong error message to give to the developer when an <A> component is used in the wrong area.

Your Example Website or App

https://stackblitz.com/edit/solidjs-templates-udovkl?file=src%2Fcomponents%2Flayout.tsx

Steps to Reproduce the Bug or Issue

    <Router>
        <A href="about">About</A> /* this is causing the error */
        <Route path="/" component={Layout}>
          <Route path="/" component={Home} />
          <Route path="/dashboard" component={Dashboard} />
        </Route>
      </Router>

You can fix this by moving the <A> component into the <Layout /> component

Expected behavior

A more user friendly error message for debugging this.

Screenshots or Videos

No response

Platform

All browsers

Additional context

This feels like a low priority item but I think having this issue documented will help someone else discover what is actually going on in their app.

Brendan-csel commented 5 months ago

Since 0.10 only <Route> components are allowed as children of <Router>. All other components that uses router context (like <A>) need to either be in a route component OR the component passed to the Router root prop.

Configure Your Routes

pixelprogrammer commented 4 months ago

Since 0.10 only <Route> components are allowed as children of <Router>. All other components that uses router context (like <A>) need to either be in a route component OR the component passed to the Router root prop.

Configure Your Routes

Thats fine. I just find that the error message is not accurate. If thats the case then the error message should include something along those lines for better feedback. Saying "Make sure your app is wrapped in a Router" feels like it may have been an old error message that doesn't really apply anymore.

ryansolid commented 4 months ago

Yeah.. good call. The wording on the error doesn't make sense anymore. That being said I wonder what would make sense. Because it is the same thing it has always been. And its generic, for whenever you use something that reads from the Router context outside of the router.

"Cannot find Router context" "<A> and 'use' router primitives can be only used inside a Route"