@idealyst/navigation 1.0.81 → 1.0.82

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idealyst/navigation",
3
- "version": "1.0.81",
3
+ "version": "1.0.82",
4
4
  "description": "Cross-platform navigation library for React and React Native",
5
5
  "readme": "README.md",
6
6
  "main": "src/index.ts",
@@ -38,8 +38,8 @@
38
38
  "publish:npm": "npm publish"
39
39
  },
40
40
  "peerDependencies": {
41
- "@idealyst/components": "^1.0.81",
42
- "@idealyst/theme": "^1.0.81",
41
+ "@idealyst/components": "^1.0.82",
42
+ "@idealyst/theme": "^1.0.82",
43
43
  "@react-navigation/bottom-tabs": "^7.0.0",
44
44
  "@react-navigation/drawer": "^7.0.0",
45
45
  "@react-navigation/native": "^7.0.0",
@@ -9,15 +9,18 @@ const NavigatorContext = createContext<NavigatorContextValue>({
9
9
  });
10
10
 
11
11
  // Utility function to parse path with parameters and find matching route
12
- const parseParameterizedPath = (path: string, routes: any[]): { routeName: string, params: Record<string, string> } | null => {
12
+ const parseParameterizedPath = (path: string, rootRoute: any): { routeName: string, params: Record<string, string> } | null => {
13
13
  // Handle absolute paths like /event/123
14
14
  if (path.startsWith('/')) {
15
15
  const pathSegments = path.split('/').filter(Boolean);
16
16
 
17
17
  // Find matching route by checking patterns like /event/:id
18
- const findMatchingRoute = (routeList: any[], segments: string[], startIndex = 0): any => {
18
+ const findMatchingRoute = (routeList: any[], segments: string[], startIndex = 0, pathPrefix = ''): any => {
19
19
  for (const route of routeList) {
20
20
  const routeSegments = route.path.split('/').filter(Boolean);
21
+ // Clean up path joining to avoid double slashes
22
+ const cleanPath = route.path.startsWith('/') ? route.path.slice(1) : route.path;
23
+ const fullRoutePath = pathPrefix ? `${pathPrefix}/${cleanPath}` : route.path;
21
24
 
22
25
  if (routeSegments.length === segments.length - startIndex) {
23
26
  let isMatch = true;
@@ -39,13 +42,18 @@ const parseParameterizedPath = (path: string, routes: any[]): { routeName: strin
39
42
  }
40
43
 
41
44
  if (isMatch) {
42
- return { route, params: extractedParams };
45
+ return { route, params: extractedParams, fullPath: fullRoutePath };
43
46
  }
44
47
  }
45
48
 
46
49
  // Check nested routes
47
50
  if (route.routes) {
48
- const nestedMatch = findMatchingRoute(route.routes, segments, startIndex + route.path.split('/').filter(Boolean).length);
51
+ const nestedMatch = findMatchingRoute(
52
+ route.routes,
53
+ segments,
54
+ startIndex + routeSegments.length,
55
+ fullRoutePath
56
+ );
49
57
  if (nestedMatch) {
50
58
  return nestedMatch;
51
59
  }
@@ -54,10 +62,10 @@ const parseParameterizedPath = (path: string, routes: any[]): { routeName: strin
54
62
  return null;
55
63
  };
56
64
 
57
- const match = findMatchingRoute([route], pathSegments);
65
+ const match = findMatchingRoute(rootRoute.routes || [], pathSegments);
58
66
  if (match) {
59
67
  return {
60
- routeName: match.route.path,
68
+ routeName: match.fullPath,
61
69
  params: match.params
62
70
  };
63
71
  }
@@ -71,10 +79,8 @@ const UnwrappedNavigatorProvider = ({ route }: NavigatorProviderProps) => {
71
79
  const navigation = useNavigation();
72
80
 
73
81
  const navigate = (params: NavigateParams) => {
74
-
75
82
  // Parse parameterized path for mobile
76
- const parsed = parseParameterizedPath(params.path, [route]);
77
-
83
+ const parsed = parseParameterizedPath(params.path, route);
78
84
  if (parsed) {
79
85
  // Navigate to the pattern route with extracted parameters
80
86
  navigation.navigate(parsed.routeName as never, parsed.params as never);
@@ -5,14 +5,12 @@ import { buildNavigator } from '../routing';
5
5
 
6
6
  const NavigatorContext = createContext<NavigatorContextValue>({
7
7
  navigate: () => {},
8
- params: {},
9
8
  });
10
9
 
11
10
  export const NavigatorProvider = ({
12
11
  route,
13
12
  }: NavigatorProviderProps) => {
14
13
  const reactRouterNavigate = useNavigate()
15
- const params = useParams()
16
14
 
17
15
  const navigateFunction = (params: NavigateParams) => {
18
16
  if (params.path) {
@@ -44,7 +42,6 @@ export const NavigatorProvider = ({
44
42
  return (
45
43
  <NavigatorContext.Provider value={{
46
44
  navigate: navigateFunction,
47
- params: params || {}
48
45
  }}>
49
46
  <RouteComponent />
50
47
  </NavigatorContext.Provider>