How to use the flux/virtualurl function in flux

To help you get started, we’ve selected a few flux examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ustwo / ustwo.com-frontend / src / node_modules / flux / router.js View on Github external
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) {
github ustwo / ustwo.com-frontend / src / node_modules / flux / router.js View on Github external
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);
  }
}
github ustwo / ustwo.com-frontend / src / node_modules / flux / router.js View on Github external
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);
  }
}