Skip to content

导航栏MenuItem.RouterLink的href属性在Hash模式路由下不正确 #1043

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

Closed
gaojinlei opened this issue Nov 25, 2020 · 1 comment
Closed

Comments

@gaojinlei
Copy link

ant-design-vue-pro version: v3

修改Router的mode为默认的hash模式后,访问路径变成http://{host}:{port}/#/{route.path},但是导航栏菜单对应的连接仍为 http://{host}:{port}/{route.path},浏览器在右键菜单新标签页打开后无法正确定位到具体页面(http://{host}:{port}/{route.path}/#/dashboard)

分析代码后,发现在使用的pro-layout组件中BaseMenu设置了routerlink的href属性,没有根据路由模式进行变化

var renderMenuItem = function renderMenuItem(h, item, i18nRender) {
  var meta = _extends({}, item.meta);
  var target = meta.target || null;
  var CustomTag = target && 'a' || 'router-link';
  var props = { to: { name: item.name } };
  var attrs = { href: item.path, target: target };
  if (item.children && item.hideChildrenInMenu) {
    // 把有子菜单的 并且 父菜单是要隐藏子菜单的
    // 都给子菜单增加一个 hidden 属性
    // 用来给刷新页面时, selectedKeys 做控制用
    item.children.forEach(function (cd) {
      cd.meta = _extends(cd.meta, { hidden: true });
    });
  }
  return h(
    MenuItem,
    { key: item.path },
    [h(
      CustomTag,
      { props: props, attrs: attrs },
      [renderIcon(h, meta.icon), renderTitle(h, meta.title, i18nRender)]
    )]
  );
}

查找pro-layout的配置,未发现解决方法。目前通过修改源文件解决该问题,是否有其它更优雅的解决方式

@sendya
Copy link
Member

sendya commented Nov 26, 2020

@sendya sendya closed this as completed Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants