Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__router.json 配置没有加 exact 选项,但是在生成后的router.js里面有这个exact #160

Closed
smithyj opened this issue Mar 5, 2018 · 3 comments · Fixed by #161

Comments

@smithyj
Copy link
Contributor

smithyj commented Mar 5, 2018

__router.json 配置没有加 exact 选项,但是在生成后的router.js里面有这个exact
复现项目地址:http://github.com/smithyj/umi.yangyj.com

@smithyj
Copy link
Contributor Author

smithyj commented Mar 5, 2018

@sorrycc
行:234
umi-bild-dev/src/FilesGenerator.js
umi-bild-dev/lib/FilesGenerator.js

 getRouterContent() {
    const { routes, config, paths } = this.service;

    const routesByPath = routes.reduce((memo, { path, component }) => {
      memo[path] = component;
      return memo;
    }, {});

    // 导出静态文件时,匹配 /index.html 到 /
    if (config.exportStatic && routesByPath['/']) {
      routesByPath['/index.html'] = routesByPath['/'];
    }

    const { loading } = config;
    let loadingOpts = '';
    if (loading) {
      loadingOpts = `loading: require('${winPath(
        join(paths.cwd, loading),
      )}').default,`;
    }
    let routesContent = Object.keys(routesByPath).map(key => {
      const pageJSFile = winPath(relative(paths.tmpDirPath, routesByPath[key]));
      debug(`requested: ${JSON.stringify(getRequest())}`);
      const isDev = process.env.NODE_ENV === 'development';

      let component;
      let isCompiling = false;
      let webpackChunkName = null;
      const compilingPath = winPath(join(__dirname, 'Compiling.js'));
      if (isDev && process.env.COMPILE_ON_DEMAND !== 'none') {
        if (getRequest()[key]) {
          component = `require('${pageJSFile}').default`;
        } else {
          component = `() => React.createElement(require('${compilingPath}').default, { route: '${key}' })`;
          isCompiling = true;
        }
      } else {
        webpackChunkName = normalizeEntry(routesByPath[key]);
        component = `dynamic(() => import(/* webpackChunkName: '${webpackChunkName}' */'${pageJSFile}'), { ${loadingOpts} })`;
      }
      component = this.service.applyPlugins('modifyRouteComponent', {
        initialValue: component,
        args: {
          isCompiling,
          pageJSFile,
          webpackChunkName,
          config,
        },
      });
     // bug 位置
      return `    <Route exact path="${key}" component={${component}} />`;
    });

@sorrycc
Copy link
Member

sorrycc commented Mar 5, 2018

router.json 自己判断是否加 exact: true

@smithyj
Copy link
Contributor Author

smithyj commented Mar 5, 2018

下一版本会修复这个吧?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants