Coder Social home page Coder Social logo

Comments (12)

molefrog avatar molefrog commented on April 30, 2024 4

@Hotell Hey! Actually, with the latest basepath update it's now possible to use nested routes! I'll compile a demo and put it in the README

from wouter.

Hotell avatar Hotell commented on April 30, 2024 4

@Hotell Hey! Actually, with the latest basepath update it's now possible to use nested routes! I'll compile a demo and put it in the README

@molefrog any news ? 🙏 Can I help in some way ?

from wouter.

molefrog avatar molefrog commented on April 30, 2024 1

Hey sorry guys, I don't think this ever will be implemented in the library. Having nesting routes seems like something that is way too beyond wouter's mission.

I do think, however, that it should be possible to write a library that implements this using wouter's standard components like Route or hooks like useLocation. I'll be glad to reference this in the library's README if someone write this packages.

Closing this 😢

from wouter.

molefrog avatar molefrog commented on April 30, 2024

@kristiandupont Hey! Thanks for the feedback!
So by relative links do you mean something like an app mounted at the static subpath, so all the routes cointain the fixed prefix?

Like /users/1 actually goes to /app/users/1?

from wouter.

kristiandupont avatar kristiandupont commented on April 30, 2024

Yes. See: https://reach.tech/router/example/nested-routes

from wouter.

midudev avatar midudev commented on April 30, 2024

Interested as well. Implementation example from react-router v.3

    <Route path="/:lang" component={RealEstateApp}>
      <Route
        path="catalogo-productos"
        component={loadUserProductCataloguePage}
      />
   </Route>

from wouter.

molefrog avatar molefrog commented on April 30, 2024

Unfortunately, nested routing isn't something that is supported at the moment and it isn't in the roadmap either. This would probably require the reimplementation of the entire library, however I do believe that you can achieve the similar behaviour by extending the default Route component. It might also require some useContext magic.

I tried to recreate this in CodeSandbox, it's not 100% working, but at least the idea:
https://codesandbox.io/s/wouter-nested-routes-ffd5h

from wouter.

molefrog avatar molefrog commented on April 30, 2024

The main problem is: wouter matches an entire url string by default, so the parent route won't be rendered. I can suggest to see how this can be implemented in React Router first, as it was the main source of the inspiration in terms of an API.

from wouter.

Hotell avatar Hotell commented on April 30, 2024

Hey sorry guys, I don't think this ever will be implemented in the library. Having nesting routes seems like something that is way too beyond wouter's mission.

I do think, however, that it should be possible to write a library that implements this using wouter's standard components like Route or hooks like useLocation. I'll be glad to reference this in the library's README if someone write this packages.

Closing this 😢

I'd suggest to put this in main Readme. as for a person coming from other common routing solutions, one would expect that following works 👉

const App = () => {
  return (
    <Switch>
      <Route path="/">
        <Home />
      </Route>
      <Route path="/topics">
        <Topics />
      </Route>
    </Switch>
  );
};

const Topics = () => {
  return (
    <Switch>
      <Route path="/topics">
        <h3>Please select a topic.</h3>
      </Route>
      <Route path="/topics/:topicId">
        <Topic />
      </Route>
    </Switch>
  );
};

WDYT ? thx

from wouter.

Hotell avatar Hotell commented on April 30, 2024

wooot! looking forward to it 👌

from wouter.

cztomsik avatar cztomsik commented on April 30, 2024

It is kinda possible (you need to wrap routes in the <Router base="...">) but it's not exactly what you might expect, because <Router> is not relative (does not respect base of its parent)

Not sure if this is by design but I think it could be fixed.

Or at least you can define your own <RelativeRouter> which would work correctly then:

const RelativeRouter = ({ children, relativeBase }) => {
  const { base } = useRouter()

  return <Router base={`${base}/${relativeBase}`}>{children}</Router>
}

and then you can do something like:

<Route path="">
  <h1>Index</h1>
  <Link to="foo"><a>Foo</a></Link>
</Route>
<RelativeRouter relativeBase="foo">
  <Route path="">
    Foo index
  </Route>
  <Route path="/bar">
    /foo/bar
  </Route>
</RelativeRouter>

and it can be nested indefinitely

from wouter.

molefrog avatar molefrog commented on April 30, 2024

Documented in the README:
https://github.com/molefrog/wouter#how-do-i-make-a-default-route

from wouter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.