@forge/react
11.18.0-next.011.18.0-next.1
out/router/components/Route.js+
out/router/components/Route.jsNew file+30
Index: package/out/router/components/Route.js
===================================================================
--- package/out/router/components/Route.js
+++ package/out/router/components/Route.js
@@ -0,0 +1,30 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.Route = void 0;
+const jsx_runtime_1 = require("react/jsx-runtime");
+const react_1 = require("react");
+const RouterContext_1 = require("./RouterContext");
+const ParamsContext_1 = require("./ParamsContext");
+const matchPath_1 = require("../utils/matchPath");
+/**
+ * Route conditionally renders its children when the current URL path matches its path prop. It must be used within a Router component.
+ *
+ * @see [Route](https://developer.atlassian.com/platform/forge/ui-kit/components/router/#route) in UI Kit documentation for more information
+ */
+const Route = ({ path, children }) => {
+ const context = (0, react_1.useContext)(RouterContext_1.RouterContext);
+ if (!context) {
+ throw new Error('Route must be used within a Router component');
+ }
+ const { location, hasMatchedRouteRef } = context;
+ if (hasMatchedRouteRef.current) {
+ return null;
+ }
+ const match = (0, matchPath_1.matchPath)(path, location.pathname);
+ if (!match) {
+ return null;
+ }
+ hasMatchedRouteRef.current = true;
+ return (0, jsx_runtime_1.jsx)(ParamsContext_1.ParamsContext.Provider, { value: match.params, children: children });
+};
+exports.Route = Route;