$route.path 中的路径通配符

Path wildcards in $route.path

在我的应用程序工具栏中,我想在用户使用 /manage/* 时显示一个后退按钮。如果用户在 /manage 或 /other 上,则不应显示后退按钮。

这是我计算的 属性 到 return true:false 如果用户在 /manage/*

computed: {
  showBackButton: function() {
    return this.$route.path === "/manage/*";
  }
}

vue-router 站点上的正则表达式文档中的通配符似乎不起作用。根据文档,* 是要使用的正确通配符。

您的代码正在进行类型和值比较,javascript 默认情况下不适用于正则表达式...如果您想使用正则表达式,我宁愿尝试类似的方法:

computed: {
  showBackButton: function() {
     return this.$route.path.match(/^\/manage\/.*$/);
  }
}