Skip to content

Commit

Permalink
fix hash support on index routes
Browse files Browse the repository at this point in the history
  • Loading branch information
marklawlor committed Mar 4, 2024
1 parent e0deb8f commit a384a1f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/expo-router/build/fork/getStateFromPath.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/expo-router/build/fork/getStateFromPath.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-router/build/fork/getStateFromPath.js.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions packages/expo-router/src/__tests__/hashs.test.ios.tsx
Expand Up @@ -114,21 +114,23 @@ it('navigating to the same route with a hash will only rerender the screen', ()
stale: true,
});

act(() => router.navigate('/?#=hash1'));
act(() => router.navigate('/?#hash1'));

expect(store.rootStateSnapshot()).toStrictEqual({
index: 0,
key: expect.any(String),
routeNames: ['index', '_sitemap', '+not-found'],
routes: [
{
name: 'index',
key: expect.any(String),
path: '/',
params: {
'#': 'hash1',
},
},
],
stale: true,
stale: false,
type: 'stack',
});
});
10 changes: 8 additions & 2 deletions packages/expo-router/src/fork/getStateFromPath.ts
Expand Up @@ -306,6 +306,7 @@ function sortConfigs(a: RouteConfig, b: RouteConfig): number {

function getStateFromEmptyPathWithConfigs(
path: string,
hash: string,
configs: RouteConfig[],
initialRoutes: InitialRouteConfig[]
): ResultState | undefined {
Expand Down Expand Up @@ -353,7 +354,7 @@ function getStateFromEmptyPathWithConfigs(
};
});

return createNestedStateObject(path, undefined, routes, configs, initialRoutes);
return createNestedStateObject(path, hash, routes, configs, initialRoutes);
}

function getStateFromPathWithConfigs(
Expand All @@ -373,7 +374,12 @@ function getStateFromPathWithConfigs(
if (!path.startsWith('/')) cleanPath = cleanPath.slice(1);

if (formattedPaths.nonstandardPathname === '/') {
return getStateFromEmptyPathWithConfigs(cleanPath, configs, initialRoutes);
return getStateFromEmptyPathWithConfigs(
cleanPath,
formattedPaths.url.hash.slice(1),
configs,
initialRoutes
);
}

// We match the whole path against the regex instead of segments
Expand Down

0 comments on commit a384a1f

Please sign in to comment.