history#createHashHistory JavaScript Examples

The following examples show how to use history#createHashHistory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: react-router-dom.js    From Learning-Redux with MIT License 6 votes vote down vote up
HashRouter =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(HashRouter, _React$Component);

  function HashRouter() {
    var _this;

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    _this.history = createHashHistory(_this.props);
    return _this;
  }

  var _proto = HashRouter.prototype;

  _proto.render = function render() {
    return React.createElement(Router, {
      history: this.history,
      children: this.props.children
    });
  };

  return HashRouter;
}(React.Component)
Example #2
Source File: react-router-dom.js    From spring-boot-ecommerce with Apache License 2.0 6 votes vote down vote up
HashRouter =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(HashRouter, _React$Component);

  function HashRouter() {
    var _this;

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    _this.history = createHashHistory(_this.props);
    return _this;
  }

  var _proto = HashRouter.prototype;

  _proto.render = function render() {
    return React.createElement(Router, {
      history: this.history,
      children: this.props.children
    });
  };

  return HashRouter;
}(React.Component)
Example #3
Source File: create-ruleset-container.js    From json-rule-editor with GNU General Public License v3.0 6 votes vote down vote up
handleAdd(e){
        e.preventDefault();
        const history = createHashHistory();
        if (!this.state.name || !this.state.name.trim()) {
            this.setState({error: {name: 'Please specify value'}});
        } else if (includes(this.props.rulesetnames, this.state.name)) {
            this.setState({ fileExist: true, message: RULE_AVAILABLE_CREATE });
        } else {
            this.props.addRuleset(this.state.name);
            history.push('./ruleset');
        }
        
    }
Example #4
Source File: hashHistory.js    From konsta with MIT License 6 votes vote down vote up
function createHashSource(basename) {
  const history = createHashHistory({ basename });
  let listeners = [];

  history.listen((location) => {
    if (history.action === 'POP') {
      listeners.forEach((listener) => listener(location));
    }
  });

  return {
    get location() {
      return history.location;
    },
    addEventListener(name, handler) {
      if (name !== 'popstate') return;
      listeners.push(handler);
    },
    removeEventListener(name, handler) {
      if (name !== 'popstate') return;
      listeners = listeners.filter((fn) => fn !== handler);
    },
    history: {
      get state() {
        return history.location.state;
      },
      pushState(state, title, uri) {
        history.push(uri, state);
      },
      replaceState(state, title, uri) {
        history.replace(uri, state);
      },
      go(to) {
        history.go(to);
      },
    },
  };
}
Example #5
Source File: app-container.js    From json-rule-editor with GNU General Public License v3.0 6 votes vote down vote up
constructor(props){
        super(props);
        const history = createHashHistory();
        if (!this.props.loggedIn) {
            history.push('./home');
        }
        this.toggleBackground = (value) => {
            const theme = { ...this.state.theme, background: value };
            document.body.className = value;
            this.setState({ theme });
        }
        this.state = {theme: { background: 'md-blue', toggleBackground: this.toggleBackground }};
    }
Example #6
Source File: navigation-link.js    From json-rule-editor with GNU General Public License v3.0 6 votes vote down vote up
NavLinks = (props) => {
    const { links } = props;
    const [visible, setVisible] = useState({0: true});
    const history = createHashHistory();
    
    
    const enableSublinks = (e, index, navigate) => {
      e.preventDefault();
      setVisible({[index]: !visible[index]});
      if (navigate) {
        history.push(navigate);
      }
      
    }

    return (links.map((link, index) => (
    <ul className="link-container" key={link.name + props.activeIndex}>
        <NavParentLink link={link} onConfirm={enableSublinks} index={index} visible={visible[index]} />
        { link.sublinks && link.sublinks.length > 0 && 
          <NavSubLink sublinks={link.sublinks} visible={visible[index]} onConfirm={props.onConfirm} activeIndex={props.activeIndex}/>
        }
    </ul>)));
}
Example #7
Source File: index.esm.js    From the-eye-knows-the-garbage with MIT License 5 votes vote down vote up
function index () {
  var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var history = opts.history || createHashHistory();
  var createOpts = {
    initialReducer: {
      router: connectRouter(history)
    },
    setupMiddlewares: function setupMiddlewares(middlewares) {
      return [routerMiddleware(history)].concat(_toConsumableArray(middlewares));
    },
    setupApp: function setupApp(app) {
      app._history = patchHistory(history);
    }
  };
  var app = create(opts, createOpts);
  var oldAppStart = app.start;
  app.router = router;
  app.start = start;
  return app;

  function router(router) {
    invariant(isFunction(router), "[app.router] router should be function, but got ".concat(_typeof(router)));
    app._router = router;
  }

  function start(container) {
    // 允许 container 是字符串,然后用 querySelector 找元素
    if (isString(container)) {
      container = document.querySelector(container);
      invariant(container, "[app.start] container ".concat(container, " not found"));
    } // 并且是 HTMLElement


    invariant(!container || isHTMLElement(container), "[app.start] container should be HTMLElement"); // 路由必须提前注册

    invariant(app._router, "[app.start] router must be registered before app.start()");

    if (!app._store) {
      oldAppStart.call(app);
    }

    var store = app._store; // export _getProvider for HMR
    // ref: https://github.com/dvajs/dva/issues/469

    app._getProvider = getProvider.bind(null, store, app); // If has container, render; else, return react component

    if (container) {
      render(container, store, app, app._router);

      app._plugin.apply('onHmr')(render.bind(null, container, store, app));
    } else {
      return getProvider(store, this, this._router);
    }
  }
}
Example #8
Source File: configureStore.prod.js    From brisque-2.0-desktop with MIT License 5 votes vote down vote up
history = createHashHistory()
Example #9
Source File: configureStore.dev.js    From brisque-2.0-desktop with MIT License 5 votes vote down vote up
history = createHashHistory()
Example #10
Source File: home-container.js    From json-rule-editor with GNU General Public License v3.0 5 votes vote down vote up
navigate(location)  {
      const history = createHashHistory();
      this.props.login();
      history.push(location); 
    }
Example #11
Source File: navigation-panel.js    From json-rule-editor with GNU General Public License v3.0 5 votes vote down vote up
handleNavLink(name) {
        const history = createHashHistory();
        this.props.setActiveRulesetIndex(name);
        history.push('./ruleset');

    }
Example #12
Source File: navigation-panel.js    From json-rule-editor with GNU General Public License v3.0 5 votes vote down vote up
handleNavBtn() {
        const history = createHashHistory();
        history.push('./create-ruleset');
    }
Example #13
Source File: appRouter.js    From veso-web with GNU General Public License v2.0 5 votes vote down vote up
history = createHashHistory()
Example #14
Source File: index.js    From the-eye-knows-the-garbage with MIT License 5 votes vote down vote up
export default function(opts = {}) {
  const history = opts.history || createHashHistory();
  const createOpts = {
    initialReducer: {
      router: connectRouter(history),
    },
    setupMiddlewares(middlewares) {
      return [routerMiddleware(history), ...middlewares];
    },
    setupApp(app) {
      app._history = patchHistory(history);
    },
  };

  const app = create(opts, createOpts);
  const oldAppStart = app.start;
  app.router = router;
  app.start = start;
  return app;

  function router(router) {
    invariant(
      isFunction(router),
      `[app.router] router should be function, but got ${typeof router}`,
    );
    app._router = router;
  }

  function start(container) {
    // 允许 container 是字符串,然后用 querySelector 找元素
    if (isString(container)) {
      container = document.querySelector(container);
      invariant(container, `[app.start] container ${container} not found`);
    }

    // 并且是 HTMLElement
    invariant(
      !container || isHTMLElement(container),
      `[app.start] container should be HTMLElement`,
    );

    // 路由必须提前注册
    invariant(app._router, `[app.start] router must be registered before app.start()`);

    if (!app._store) {
      oldAppStart.call(app);
    }
    const store = app._store;

    // export _getProvider for HMR
    // ref: https://github.com/dvajs/dva/issues/469
    app._getProvider = getProvider.bind(null, store, app);

    // If has container, render; else, return react component
    if (container) {
      render(container, store, app, app._router);
      app._plugin.apply('onHmr')(render.bind(null, container, store, app));
    } else {
      return getProvider(store, this, this._router);
    }
  }
}
Example #15
Source File: store.js    From juggernaut-desktop with MIT License 5 votes vote down vote up
history = createHashHistory()
Example #16
Source File: store.js    From secure-electron-template with MIT License 5 votes vote down vote up
{
  routerMiddleware,
  createReduxHistory,
  routerReducer
} = createReduxHistoryContext({
  history: createHashHistory()
})
Example #17
Source File: index.js    From pineapple with MIT License 5 votes vote down vote up
history = createHashHistory()
Example #18
Source File: index.js    From app-personium-trails with Apache License 2.0 5 votes vote down vote up
history = createHashHistory()
Example #19
Source File: store.js    From github-azure-demo with MIT License 5 votes vote down vote up
history = createHashHistory()
Example #20
Source File: index.js    From gobench with Apache License 2.0 5 votes vote down vote up
history = createHashHistory()
Example #21
Source File: configureStore.prod.js    From NoteMaster with GNU General Public License v3.0 5 votes vote down vote up
history = createHashHistory()
Example #22
Source File: configureStore.dev.js    From NoteMaster with GNU General Public License v3.0 5 votes vote down vote up
history = createHashHistory()