plugins/rekit-react/route.js
function add(elePath, args) {
  if (!args || !args.urlPath) return;
  const ele = parseElePath(elePath, 'component');
  const routePath = `src/features/${ele.feature}/route.js`;
  if (!vio.fileExists(routePath)) {
    throw new Error(`route.add failed: file not found ${routePath}`);
  }

  const { urlPath } = args;
  refactor.addImportFrom(routePath, './', '', ele.name);

  const ast1 = ast.getAst(routePath, true);
  const arrNode = getChildRoutesNode(ast1);
  if (arrNode) {
    const rule = `{ path: '${urlPath}', component: ${ele.name}${
      args.isIndex ? ', isIndex: true' : ''
    } }`;
    const changes = refactor.addToArrayByNode(arrNode, rule);
    const code = refactor.updateSourceCode(vio.getContent(routePath), changes);
    vio.save(routePath, code);
  } else {
    throw new Error(
      `You are adding a route rule, but can't find childRoutes property in '${routePath}', please check.`
    );
  }
}
function add(elePath, args) {
  if (!args || !args.urlPath) return;
  const ele = parseElePath(elePath, 'component');
  const routePath = `src/features/${ele.feature}/route.js`;
  if (!vio.fileExists(routePath)) {
    throw new Error(`route.add failed: file not found ${routePath}`);
  }

  const { urlPath } = args;
  refactor.addImportFrom(routePath, './', '', ele.name);

  const ast1 = ast.getAst(routePath, true);
  const arrNode = getChildRoutesNode(ast1);
  if (arrNode) {
    const rule = `{ path: '${urlPath}', component: ${ele.name}${
      args.isIndex ? ', isIndex: true' : ''
    } }`;
    const changes = refactor.addToArrayByNode(arrNode, rule);
    const code = refactor.updateSourceCode(vio.getContent(routePath), changes);
    vio.save(routePath, code);
  } else {
    throw new Error(
      `You are adding a route rule, but can't find childRoutes property in '${routePath}', please check.`
    );
  }
}
function add ( elePath , args ) { if ( ! args || ! args . urlPath ) return ; const ele = parseElePath ( elePath , 'component' ) ; const routePath = ` ${ ele . feature } ` ; if ( ! vio . fileExists ( routePath ) ) { throw new Error ( ` ${ routePath } ` ) ; } const { urlPath } = args ; refactor . addImportFrom ( routePath , './' , '' , ele . name ) ; const ast1 = ast . getAst ( routePath , true ) ; const arrNode = getChildRoutesNode ( ast1 ) ; if ( arrNode ) { const rule = ` ${ urlPath } ${ ele . name } ${ args . isIndex ? ', isIndex: true' : '' } ` ; const changes = refactor . addToArrayByNode ( arrNode , rule ) ; const code = refactor . updateSourceCode ( vio . getContent ( routePath ) , changes ) ; vio . save ( routePath , code ) ; } else { throw new Error ( ` ${ routePath } ` ) ; } }
Add component to a route.js under a feature. It imports all component from index.js
Add component to a route . js under a feature . It imports all component from index . js