Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function navigate (urlString, history, ignoreUrl, replaceState, force) {
const vurl = virtualUrl(urlString);
const pathname = vurl.pathname;
let action;
let params;
let route = find(routes, (route) => {
return RoutePattern.fromString(route.pattern).matches(pathname);
});
if (route) {
action = route.handler,
params = RoutePattern.fromString(route.pattern).match(pathname).params;
params.push(mapValues(vurl.searchObject, value => camelCase(value)));
} else {
action = notfound;
params = [pathname];
}
if (!ignoreUrl) {
function setUrl (url, replace) {
const vurl = virtualUrl(url);
const name = manifest.name;
vurl.href = url;
if (replace) {
window.history.replaceState(null, name, url);
} else {
window.history.pushState(null, name, url);
}
}
function init (initialUrl) {
const vurl = virtualUrl(initialUrl || window.location.href);
window.onpopstate = () => {
let url = window.location.href;
if(window.location.href.indexOf('#') > -1) {
url = window.location.hash.substr(1);
}
Router.navigate(url, true, true);
};
if (!RoutePattern.fromString(routes.home.pattern).matches(vurl.pathname)) {
Router.navigate(vurl.original, false, false, true, true);
} else {
setUrl(vurl.original, true);
routes.home.handler(vurl.searchObject);
}
}