piral-core
Version:
The core library for creating a Piral instance.
27 lines • 1.26 kB
JavaScript
import * as React from 'react';
//@ts-ignore
import { Switch, Route, useParams, useLocation } from 'wouter';
function getHistory(navigate) {
return {
push(path, state) {
navigate(path, { replace: false, state });
},
replace(path, state) {
navigate(path, { replace: true, state });
},
};
}
const RouteContentWrapper = ({ Component }) => {
const params = useParams();
const [pathname, navigate] = useLocation();
return (React.createElement(Component, { history: getHistory(navigate), location: { hash: location.hash, pathname, search: location.search, state: undefined }, match: { params, isExact: true, path: pathname, url: location.href } }));
};
export const DefaultRouteSwitch = ({ paths, NotFound, ...props }) => {
return (React.createElement(Switch, { ...props },
paths.map(({ path, Component }) => (React.createElement(Route, { key: path, path: path },
React.createElement(RouteContentWrapper, { Component: Component })))),
React.createElement(Route, null,
React.createElement(RouteContentWrapper, { Component: NotFound }))));
};
DefaultRouteSwitch.displayName = 'DefaultRouteSwitch';
//# sourceMappingURL=DefaultRouteSwitch_wouter.js.map