const sinks$ = sources.History.map(({pathname}) => {

    // use switchpath to marry up our current url with component
    const pathAndValue = switchPath(pathname, {
      '/': Home,
      '/page1': Page1,
      '/page2': Page2,
      '*': Page404,
    });

    // the result from the switchpath
    const component = pathAndValue.value;

    // isolate the component will help if using templates
    //const Component = isolate(component);
    const Component$ = component(sources);

    // check if the page/component has a Props value and if so pass it on
    const Props$ = Component$.Props ? sources.Props = Component$.Props : sources.Props;

    return {
      Comp: Component$,
      Props: Props$.share() // return our Props$ to current page/component
    };
  }).shareReplay(1); // make sure sinks$ are hot
示例#2
0
/**
 * Workaround for issues with switch-path finding the * parameter
 * @private
 * @method getPathValue
 * @param  {string}     pathname    the route to match against
 * @param  {Object}     definitions route definitions object as defined by
 * switch-path
 * @return {Object}                 an object containing the path matched
 * and the value associated with that route.
 */
function getPathValue(pathname, definitions) {
  let path
  let value
  try {
    const match = switchPath(pathname, definitions)
    value = match.value
    path = match.path
  } catch (e) {
    // try handling default route
    if (definitions[`*`]) {
      path = pathname
      value = definitions[`*`]
    } else {
      throw e
    }
  }
  return {path, value}
}