You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Returns the current route's path parameters. Note that route components also receive `params` as a prop, so this hook is mainly useful for non-route components that need access to params.
155
155
156
156
```tsx
157
157
// Route: /users/:id
@@ -182,10 +182,31 @@ setSearchParams((prev) => {
182
182
183
183
#### `RouteDefinition`
184
184
185
+
Route components receive a `params` prop with the matched path parameters. Use the `route()` helper for type-safe route definitions:
186
+
187
+
```typescript
188
+
import { route } from"@funstack/router";
189
+
190
+
// Route without loader - component receives params prop
Note: RouteContext remains unchanged - it doesn't need to store the data since it's passed directly as a prop.
256
+
Note: RouteContext remains unchanged - it doesn't need to store the data since it's passed directly as a prop. Params are also passed as props for consistency and type safety.
236
257
237
258
### 3. Loader Execution Strategy
238
259
@@ -279,8 +300,12 @@ function RouteRenderer({
279
300
return (
280
301
<RouteContext.Providervalue={routeContextValue}>
281
302
{Component ? (
282
-
// Pass data as prop if loader exists
283
-
data !== undefined ? <Componentdata={data} /> : <Component />
303
+
// Always pass params, pass data only if loader exists
304
+
route.loader ? (
305
+
<Componentdata={data} params={params} />
306
+
) : (
307
+
<Componentparams={params} />
308
+
)
284
309
) : (
285
310
outlet
286
311
)}
@@ -488,19 +513,24 @@ const data = useLoaderData(); // Returns resolved data
488
513
489
514
### FUNSTACK Router (This Design)
490
515
491
-
FUNSTACK passes loader result as a prop, component handles it:
516
+
FUNSTACK passes loader result and params as props, component handles them:
// FUNSTACK - sync loader, component receives value directly
501
-
function SettingsPage({ data}: { data:Settings }) {
525
+
// FUNSTACK - sync loader, component receives value and params directly
526
+
function SettingsPage({ data, params}: { data:Settings; params: {} }) {
502
527
return <div>{data.theme}</div>;
503
528
}
529
+
530
+
// FUNSTACK - no loader, component receives only params
531
+
function AboutPage({ params }: { params: {} }) {
532
+
return <div>About</div>;
533
+
}
504
534
```
505
535
506
536
**Advantages of our approach**:
@@ -517,7 +547,8 @@ function SettingsPage({ data }: { data: Settings }) {
517
547
The data loader feature adds:
518
548
519
549
1. `loader` property on route definitions (can return Promise or value)
520
-
2.`data` prop passed to route components
521
-
3. Loader result caching to prevent duplicate execution
550
+
2. `data` prop passed to route components (when loader is defined)
551
+
3. `params` prop passed to all route components (with types inferred from path pattern)
552
+
4. Loader result caching to prevent duplicate execution
522
553
523
-
Components receive loader results as props and handle Promises with React's `use()` hook when needed, giving maximum flexibility while keeping the router simple.
554
+
Components receive loader results and params as props and handle Promises with React's `use()` hook when needed, giving maximum flexibility while keeping the router simple.
@@ -298,19 +306,15 @@ The Navigation API is supported in:
298
306
299
307
- Chrome 102+
300
308
- Edge 102+
309
+
- Safari 26.2+
301
310
- Opera 88+
302
311
303
-
For unsupported browsers (Firefox, Safari), a polyfill or fallback strategy will be needed. Options:
312
+
Firefox does not yet support the Navigation API.
304
313
305
-
1. Use the `navigation-api-polyfill` package
306
-
2. Provide a History API fallback mode
307
-
3. Require polyfill as peer dependency
308
-
309
-
**Initial implementation will target Navigation API-supporting browsers only.**
314
+
For unsupported browsers, use the `fallback="static"` option on the Router component, which renders matched routes without SPA navigation capabilities (links cause full page loads).
310
315
311
316
## Future Considerations
312
317
313
-
-**Data loading**: Route-based data fetching (loaders)
314
318
-**Pending UI**: Navigation state for loading indicators
315
319
-**View Transitions**: Integration with View Transitions API
316
320
-**Scroll restoration**: Automatic scroll position management
0 commit comments