Vue.js 的通配符路由
Wildcard routes with Vue.js
我正在尝试像这样匹配 Vue.js 路线:
{
path: '/#/reset*',
name: 'Confirm Reset Password',
meta: { title: `Confirm password reset` },
component: ConfirmResetPassword
},
到 URL 看起来像这样
mywebsite.com/#/reset-password
但它不起作用 - 由于某种原因它只是转到主页。我是在使用通配符还是在保留命名空间中使用了“#”?
我也有这两条路线:
{
path: '/',
name: 'Home',
component: Home
},
{
path: '*',
name: '404',
meta: { title: `Page not found` },
component: Error404
}
**编辑
我打开了历史记录模式,URL 是从 Django 后端生成的
/#
不应该是 path
的一部分。像下面这样使用:
{
path: '/reset*',
name: 'Confirm Reset Password',
meta: { title: `Confirm password reset` },
component: ConfirmResetPassword
},
你的 URL 中有 /#
是因为你没有打开历史模式(这不是问题,它只是使用 vue-router 的一种不同方式)。所以你在没有 /#
.
的情况下声明你的路径
如果启用了历史记录模式,我将无法匹配前缀为“#”的 URL - 解决方案是更改在后端生成的 URL。
我正在尝试像这样匹配 Vue.js 路线:
{
path: '/#/reset*',
name: 'Confirm Reset Password',
meta: { title: `Confirm password reset` },
component: ConfirmResetPassword
},
到 URL 看起来像这样
mywebsite.com/#/reset-password
但它不起作用 - 由于某种原因它只是转到主页。我是在使用通配符还是在保留命名空间中使用了“#”?
我也有这两条路线:
{
path: '/',
name: 'Home',
component: Home
},
{
path: '*',
name: '404',
meta: { title: `Page not found` },
component: Error404
}
**编辑
我打开了历史记录模式,URL 是从 Django 后端生成的
/#
不应该是 path
的一部分。像下面这样使用:
{
path: '/reset*',
name: 'Confirm Reset Password',
meta: { title: `Confirm password reset` },
component: ConfirmResetPassword
},
你的 URL 中有 /#
是因为你没有打开历史模式(这不是问题,它只是使用 vue-router 的一种不同方式)。所以你在没有 /#
.
如果启用了历史记录模式,我将无法匹配前缀为“#”的 URL - 解决方案是更改在后端生成的 URL。