molefrog / wouter

🥢 A minimalist-friendly ~2.1KB routing for React and Preact
https://npm.im/wouter
The Unlicense
6.65k stars 152 forks source link

[Bug] Can't match default <Route>Not found</Route> when Router inside Switch #394

Closed CodingReaction closed 10 months ago

CodingReaction commented 10 months ago

Hi, i created an example of the issue. If you try matching "/anything" or "/auth/whatever" it doesn't match with the last one that contains the "Not found" text.

Try commenting the ... block to see the expected behaviour. I'm using Google Chrome 120.0.6099.71 on Ubuntu 22 (not sure if is relevant data).

https://replit.com/@CodingReaction/WouterNoMatchError

Did i miss something on the Docs? Thanks.

molefrog commented 10 months ago

Hey, @CodingReaction. I don't think Router inside Switch is supported. Consider using the latest version where nested routing comes out-of-the-box.

molefrog commented 10 months ago

Oh, and I'm not completely sure, but this hack might help:

<Switch>
    <Route path="/" component={IndexPag} />
    <Router path="/auth/:rest*" base="/auth">
      <Route path="/login" component={LoginPag} />
    </Router>
    <Route>Not found </Route>
  </Switch>

Though, I would still prefer the v3.

CodingReaction commented 10 months ago

Thanks @molefrog for the clarifications! It's true that Switch doesn't seems to be supported with a Router inside, i think that my previous experience with old versions of react-router-dom contributed to the confusion.

Cheers!