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

[Feature]: 在路由守卫里提供阻断子应用跳转的方法 #1520

Open
lvboda opened this issue Feb 8, 2025 · 0 comments
Open

[Feature]: 在路由守卫里提供阻断子应用跳转的方法 #1520

lvboda opened this issue Feb 8, 2025 · 0 comments

Comments

@lvboda
Copy link

lvboda commented Feb 8, 2025

Is your feature request related to a problem? Please describe.
router.beforeEach 的回调里没有提供 next 参数或者根据返回值 true 或 false 决定子应用是否跳转。我的场景是代理子应用的某些路由跳转到主应用的地址,因为没法阻断子应用跳转会导致主应用跳转前子应用跳转页面会闪一下。

Describe the solution you'd like
router.beforeEach 回调的参数里增加 next 函数或者增加根据返回值 boolean 来决定是否跳转的逻辑。

Describe alternatives you've considered
我目前的做法是直接 location.href 跳转并同步阻塞住子应用跳转。

Additional context
我期望的做法:

microApp.router.beforeEach((to, from, appName, next) => {
  if (to.pathname === '/bi/overview') {
    history.push('/report/overview');
    return;
  }

  next();
});

我目前的做法:

microApp.router.beforeEach((to, from) => {
  if (to.pathname === '/bi/overview') {
    window.location.href = '/report/overview';
    // 为了阻止子应用继续跳转这里做同步阻塞
    const start = Date.now();
    while (Date.now() - start < 1000) {}
  }
});
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

1 participant