Comments (12)
@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 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.
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.
@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.
Yes. See: https://reach.tech/router/example/nested-routes
from wouter.
Interested as well. Implementation example from react-router v.3
<Route path="/:lang" component={RealEstateApp}>
<Route
path="catalogo-productos"
component={loadUserProductCataloguePage}
/>
</Route>
from wouter.
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.
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.
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 likeuseLocation
. 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.
wooot! looking forward to it 👌
from wouter.
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.
Documented in the README:
https://github.com/molefrog/wouter#how-do-i-make-a-default-route
from wouter.
Related Issues (20)
- Route not accessible from multiple routers with different base HOT 1
- Bun install invalid hook call HOT 4
- Router don't work with Preact (10.18.1) HOT 3
- wouter-preact: Params with typescript? HOT 2
- How to add params in a nesting route? HOT 3
- v2.12.1 npm package is out of sync with v2.12.1 tag HOT 1
- v3.0.0-rc.1: When use hash router, Ctrl+click on <Link>, new window is opened with wrong url HOT 3
- Potential `useSearch` bug not triggering updates when used with `urql` HOT 9
- [Bug] Can't match default <Route>Not found</Route> when Router inside Switch HOT 3
- (?) Hash routing with no prefix slash index.html#/example/path/ HOT 3
- useSearch unsafe parameter decoding HOT 3
- v3.0.0-rc.2 decodeUriComponent is called before route match, breaking links with urlencoded slash (%2F) HOT 2
- v3.0.0-rc.1: `useRoute` should allow `nest` option just like `<Route />` HOT 1
- Suggestion: `<Link>` should always render an `<a>` (or at least have the option to do so) HOT 5
- Accessing nested params with `useParams` HOT 8
- Nested routing broken by intermediate component HOT 2
- Exit animation with framer-motion HOT 7
- How to use V3 with Jest? HOT 3
- [BUG] `useHashLocation` not syncing with state HOT 3
- Docs don't say how to install; no readme on NPM page HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wouter.