Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
15f1913
Site Editor: Use permalinks instead of query args and site-editor.php…
youknowriad Nov 21, 2024
edd3075
Fix some bugs
youknowriad Nov 21, 2024
6a4cc01
Fix dashboard links
youknowriad Nov 21, 2024
937ebf0
Add basic redirection
youknowriad Nov 21, 2024
c3bff73
Add server side permanent redirects for the old urls
youknowriad Nov 21, 2024
2c0b7f7
Fix the posts dataviews
youknowriad Nov 21, 2024
3c9a42c
Small fix
youknowriad Nov 21, 2024
b811a48
Remove url rewrites
youknowriad Nov 21, 2024
5153567
Fix theme previewing
youknowriad Nov 25, 2024
bc404a3
Fix query string argument
youknowriad Nov 25, 2024
b4d15dc
switch middleware to beforeNavigate
youknowriad Nov 25, 2024
e8ec07a
Filter instead of action
youknowriad Nov 25, 2024
a3324ac
Move the code to 6.8 folder
youknowriad Nov 25, 2024
2b9d0bd
Refactor deprecations
youknowriad Nov 25, 2024
5a51c5a
Set the right path to avoid redirections
youknowriad Nov 25, 2024
b03d304
Fix e2e tests
youknowriad Nov 25, 2024
551674f
Fix hybrid themes
youknowriad Nov 25, 2024
0bce3ba
Simplify redirects
youknowriad Nov 26, 2024
29eb798
Add useLocation check
youknowriad Nov 26, 2024
ff1411c
useEvent to avoid memoization
youknowriad Nov 26, 2024
e46b7ef
Return a promise from navigate
youknowriad Nov 27, 2024
544fe66
Memoize route recognizer
youknowriad Nov 27, 2024
97a7ee7
Add a comment
youknowriad Nov 27, 2024
233fa6b
Fix e2e test
youknowriad Nov 27, 2024
7fb975e
Add backport PR
youknowriad Nov 27, 2024
2e4c03d
Remove posts redirectins
youknowriad Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Memoize route recognizer
  • Loading branch information
youknowriad committed Nov 27, 2024
commit 544fe66860232c18872b01afcf92f509b8c09a16
21 changes: 12 additions & 9 deletions packages/router/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,12 @@ export function useHistory() {

export default function useMatch(
location: LocationWithQuery,
routes: Route[],
matcher: RouteRecognizer,
pathArg: string
): Match {
const { query: rawQuery = {} } = location;

return useMemo( () => {
const matcher = new RouteRecognizer();
routes.forEach( ( route ) => {
matcher.add( [ { path: route.path, handler: route } ], {
as: route.name,
} );
} );
const { [ pathArg ]: path = '/', ...query } = rawQuery;
const result = matcher.recognize( path )?.[ 0 ];
if ( ! result ) {
Expand Down Expand Up @@ -199,7 +193,7 @@ export default function useMatch(
query,
path: addQueryArgs( path, query ),
};
}, [ routes, rawQuery, pathArg ] );
}, [ matcher, rawQuery, pathArg ] );
}

export function RouterProvider( {
Expand All @@ -218,7 +212,16 @@ export function RouterProvider( {
getLocationWithQuery,
getLocationWithQuery
);
const match = useMatch( location, routes, pathArg );
const matcher = useMemo( () => {
const ret = new RouteRecognizer();
routes.forEach( ( route ) => {
ret.add( [ { path: route.path, handler: route } ], {
as: route.name,
} );
} );
return ret;
}, [ routes ] );
const match = useMatch( location, matcher, pathArg );
const config = useMemo(
() => ( { beforeNavigate, pathArg } ),
[ beforeNavigate, pathArg ]
Expand Down