How to use rax-use-router - 5 common examples

To help you get started, we’ve selected a few rax-use-router 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 alibaba / rax / packages / universal-app-runtime / src / router.js View on Github external
function Router(props) {
    const [currentPath, setCurrentPath] = useState('');

    // return initial component in ssr
    if (isNode && routerConfig.InitialComponent) {
      return createElement(routerConfig.InitialComponent, props);
    }

    const { component } = RaxUseRouter.useRouter(() => _routerConfig);

    if (!component || Array.isArray(component) && component.length === 0) {
      // Return null directly if not matched.
      return null;
    } else {
      // process Page.getInitialProps
      if (isWeb && _currentPagePath !== _history.location.pathname) {
        _initialProps = {};
        _currentPagePath = _history.location.pathname;
        // SSR project the first time is initialized from global data,
        // after that the data will be obtained from the component's own getInitialProps
        if (_initialPropsFromSSR !== null && !_isReadInitialPropsFromSSR) {
          // After routing switching, it is considered not the first rendering.
          _initialProps = _initialPropsFromSSR;
          _isReadInitialPropsFromSSR = true;
        } else if (component.getInitialProps) {
github alibaba / rax / packages / rax-app / src / runApp.web.js View on Github external
function Entry(props) {
  const { history } = props;
  const { component } = useRouter(() => props);

  // For async getInitialProps method update Entry component.
  const [tempPath, setTempPath] = useState('');

  if (!component || Array.isArray(component) && component.length === 0) {
    // Return null directly if not matched.
    return null;
  } else {
    // TODO new SSR app.js
    if (component.getInitialProps && currentPagePath !== history.location.pathname) {
      pageInitialProps = {};
      currentPagePath = history.location.pathname;
      component.getInitialProps().then((props) => {
        pageInitialProps = props;
        setTempPath(currentPagePath);
      }).catch(() => {
github alibaba / rax / packages / rax-app / src / runApp.weex.js View on Github external
function Entry(props) {
  const { component } = useRouter(() => props);
  if (!component || Array.isArray(component) && component.length === 0) {
    // Return null directly if not matched.
    return null;
  } else {
    return createElement(component, { ...props });
  }
}
github alibaba / rax / packages / rax-app / src / runApp.js View on Github external
function App(props) {
  const { appConfig, history, routes, InitialComponent } = props;
  const { component } = useRouter(() => ({ history, routes, InitialComponent }));

  if (isNullableComponent(component)) {
    // Return null directly if not matched.
    return null;
  } else {
    const [pageInitialProps, setPageInitialProps] = useState(
      // If SSR is enabled, set pageInitialProps: {pagePath: pageData}
      initialDataFromSSR ? { [initialDataFromSSR.pagePath || '']: initialDataFromSSR.pageData || {} } : {}
    );

    // If SSR is enabled, process getInitialProps method
    if (isWeb && initialDataFromSSR && component.getInitialProps && !pageInitialProps[component.__path]) {
      useEffect(() => {
        const getInitialPropsPromise = component.getInitialProps();

        // Check getInitialProps returns promise.
github alibaba / rax / packages / rax-pwa / src / createRouter.js View on Github external
return function(props) {
    routerProps = { ...props, router };

    if (InitialComponent) {
      routerConfig.InitialComponent = ;
    }

    const { component } = useRouter(routerConfig);
    const [updateTemp, setUpdateTemp] = useState(null);

    updateComponentTrigger = setUpdateTemp;
    if (!withPageAlive) {
      return component;
    } else {
      let cachePageMatched = false;
      return (
        <div style="{{">
          {Object.keys(alivePageCache).map((pageName) =&gt; {
            cachePageMatched = isPathMatched(withSSR ? 'history' : 'hash', alivePageCache[pageName].regexp, pageName);
            const element = alivePageCache[pageName].component;
            if (cachePageMatched &amp;&amp; element === null) {
              activateAlivePageComponent(pageName);
            }
            if (cachePageMatched &amp;&amp; alivePageCache[pageName].title) {</div>

rax-use-router

Rax useRouter hook.

BSD-3-Clause
Latest version published 3 years ago

Package Health Score

46 / 100
Full package analysis

Popular rax-use-router functions

Similar packages