-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoute.js
23 lines (20 loc) · 985 Bytes
/
Route.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import Didact from './Didact'; // Adjust based on your actual exports
import { routingContext } from './RoutingContext';
// Assuming you've set up RoutingContext and useContext similarly to React
export default function Route({ path, component, exact = false }) {
// console.log('Route component for path:', path);
const route = Didact.useContext(routingContext); // Accessing the current route from context
// console.log('Route context : ', route);
const match = exact ? route.path === path : route.path.startsWith(path);
// Exact match vs. startsWith allows for nested routes if exact is false
console.log('Route component : ', component, ' with path : ', path);
if (match) {
// console.log('Match found for path:', path);
// If there's a match, render the specified component
// Your library's syntax for rendering a component might differ
return component();
} else {
// If no match, render nothing or an alternative
return null;
}
}