-
-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add absolute paths for routers using base #153
Conversation
Codecov Report
@@ Coverage Diff @@
## master #153 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 7 7
Lines 237 239 +2
Branches 48 50 +2
=========================================
+ Hits 237 239 +2
Continue to review full report at Codecov.
|
@@ -67,7 +67,7 @@ Wouter provides a simple API that many developers and library authors appreciate | |||
- [TypeScript support](#can-i-use-wouter-in-my-typescript-project) | |||
- [Using with Preact](#preact-support) | |||
- [Server-side Rendering (SSR)](#is-there-any-support-for-server-side-rendering-ssr) | |||
- [Routing in less than 350B](#1kb-is-too-much-i-cant-afford-it) | |||
- [Routing in less than 400B](#1kb-is-too-much-i-cant-afford-it) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated here since 350B was not true anymore (even before this PR). I've put 400 since it's still a nice goal, and it allows for a bit of changes since the size is now 380.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good one!
@@ -332,7 +332,7 @@ Read more → [Customizing the location hook](#customizing-the-location-hook). | |||
- **`matcher: (pattern: string, path: string) => [match: boolean, params: object]`** — a custom function used for matching the current location against the user-defined patterns like `/app/users/:id`. Should return a match result and an hash of extracted parameters. It should return `[false, null]` when there is no match. | |||
|
|||
- **`base: string`** — an optional setting that allows to specify a base path, such as `/app`. All application routes | |||
will be relative to that path. | |||
will be relative to that path. Prefixing a route with `~` will make it absolute, bypassing the base path. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I tried to be as succinct as possible to match the style of the ReadMe. I can elaborate a bit (maybe with samples?) as this might not be clear enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, definitely a good idea! I'm going to work on an example, already have some ideas for the demo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work!
All looks great, I've merged into the master branch. The further steps are:
|
Awesome, thanks! I can put together one or two CodeSandbox examples if you want. I was thinking something along the line of: MyAppOne / MyAppTwo with two subpages each, with MyAppOne having a link to a subpage of MyAppTwo, and vice-versa. |
Here is a first go I had with a sandbox: Of course it is not working right now, since it uses current wouter release. |
@jvdsande I've just published UPD: I forked the sandbox and it appears to be working! |
This PR is linked to issue #152.
~
are always handled as absolute paths, even inside aRouter
usingbase
href
attribute accordinglyuseLocation
returnslocation
accordingly, thus makingmatcher
work without any changes neededRoute
,Redirect
,useLocation
andLink
Taking the following sample:
The first
Link
will point to/app/relative
, while the second points to/absolute
Taking the following sample:
Redirect
will match/app
and redirect to/app/subpage
. It will not match/
which will be reported as~/
inside theRouter
.