Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function insertCss(...styles) {
const removeCss = styles.map(x => x._insertCss());
return () => removeCss.forEach(f => f());
}
function redirect(to) {
history.replace(to);
}
const context = { insertCss, store };
const mnt = document.querySelector("main");
const router = new Router(routes);
async function bootstrap(location, router) {
if (FIRST_RENDER) {
if (!_DEV_) await registerServiceWorker();
if (!self.fetch) {
await import("unfetch" /* webpackChunkName: "fetch-polyfill" */);
}
}
CURRENT_LOCATION = location;
const { pathname: path, search } = location;
const route = await router.resolve({ path, store, redirect, search, ...routerMiddleware });
const render = async (location: Location, Routes: typeof routes) => {
if (routes) currentRoutes = Routes
const Router = new UniversalRouter(currentRoutes, {
resolveRoute,
context: { store },
})
const Route = await Router.resolve({
pathname: location.pathname,
})
return renderComponent({Route})
}
const render = async (location: Location, Routes: typeof routes) => {
if (routes)
currentRoutes = Routes
const Router = new UniversalRouter(currentRoutes, { resolveRoute, context: { store } })
const Route = await Router.resolve({ pathname: location.pathname })
return renderComponent({Route})
}
debug('isSetup', store.status.isSetup);
if (!store.status.isSetup && !pathname.startsWith('/seed')) {
return { redirect: '/seed' };
}
},
children: [
...modules.auth.routes,
...modules.catalog.routes,
...modules.configuration.routes,
...modules.administrate.routes,
...modules.basket.routes,
...modules.orders.routes
]
};
return new Router(routes, {
resolveRoute(routerContext: UniversalRouterContext, params: any) {
const { route } = routerContext;
if (typeof route.action === 'function') {
const result = route.action(routerContext, params);
if (result) {
return result;
}
}
if (typeof route.component === 'function') {
return route.component(routerContext);
}
}
});
}
initRouter() {
this.router = new UniversalRouter(this.routes);
}
import UniversalRouter from 'universal-router';
import createHistory from 'history/createBrowserHistory'
import { hydrate } from 'react-dom';
import routes from '../both/routes'
const History = createHistory()
const location = History.location
const router = new UniversalRouter(routes);
function renderLocation(location) {
return router.resolve({pathname: location.pathname}).then(route => {
//route is what our action() returns for a specific path
document.title = route.title;
hydrate(route.component, document.getElementById("app"));
});
}
//Initialize the first page render with current History
renderLocation(location);
//listen to URL(location) changes and render the new layout based on URL automatically
History.listen((anylocation) => {renderLocation(anylocation)});
export { History };
async run(props = {}) {
await super.run();
const context = this.provide();
this.log.trace('router.context', Object.keys(context))
this.routes = this.getRoutes();
this.router = new UniversalRouter(this.routes, {
context,
});
if (__CLIENT__ && !__DEV__) {
setTimeout(() => this.checkVersion(), 120 * 1000);
}
}
export default routes => new Router(routes, {
resolveRoute(context, params) {
if (typeof context.route.load === 'function') {
return context.route.load().then(action => action.default(context, params));
}
if (typeof context.route.action === 'function') {
return context.route.action(context, params);
}
return null;
},
});