packages/uni-router/src/router.js
function router(req, resp, next) {
    const routerPath = req.routePath || '';

    const beforeRunMiddleware = (route) => {
      const match = matchRoute(routerPath, req, route);
      if (!match) return false;

      const { params, path: matchPath } = match;

      if (options.params) req.params = { ...options.params, ...params };
      else req.params = params;

      // dynamically set req.routePath for the route
      req.routePath = routerPath + matchPath;
      return true;
    };
    const routeStack = compose(router.routes, { beforeRunMiddleware });

    return routeStack.call(this, req, resp, () => {
      req.routePath = routerPath;// restore routePath
      return next && next();
    });
  }
function router(req, resp, next) {
    const routerPath = req.routePath || '';

    const beforeRunMiddleware = (route) => {
      const match = matchRoute(routerPath, req, route);
      if (!match) return false;

      const { params, path: matchPath } = match;

      if (options.params) req.params = { ...options.params, ...params };
      else req.params = params;

      // dynamically set req.routePath for the route
      req.routePath = routerPath + matchPath;
      return true;
    };
    const routeStack = compose(router.routes, { beforeRunMiddleware });

    return routeStack.call(this, req, resp, () => {
      req.routePath = routerPath;// restore routePath
      return next && next();
    });
  }
function router ( req , resp , next ) { const routerPath = req . routePath || '' ; const beforeRunMiddleware = ( route ) => { const match = matchRoute ( routerPath , req , route ) ; if ( ! match ) return false ; const { params , path : matchPath } = match ; if ( options . params ) req . params = { ... options . params , ... params } ; else req . params = params ; // dynamically set req.routePath for the route req . routePath = routerPath + matchPath ; return true ; } ; const routeStack = compose ( router . routes , { beforeRunMiddleware } ) ; return routeStack . call ( this , req , resp , ( ) => { req . routePath = routerPath ; // restore routePath return next && next ( ) ; } ) ; }
the router instance
the router instance