我现在正在学习Vue 2个星期,我找不到关于路由安全性这个问题的答案.
当我在Vue中使用元字段和路由保护来保护路由时,我想知道客户端可以做什么来查看组件.
const router = new VueRouter({
routes: [
{
path: '/foo',
component: Foo,
children: [
{
path: 'bar',
component: Bar,
// a meta field
meta: { requiresAuth: true }
}
]
}
]
})
router.beforeEach((to, from, next) => {
// check if authenticated by jwt from store or localstorage
})
Run Code Online (Sandbox Code Playgroud)
该路由/foo/bar受beforeEach挂钩和requiresAuth元字段的保护.但所有这些代码都在客户端(作为缩小版本,但仍然存在).用户可以更改代码并查看组件.
我知道我必须再次保护后端的所有api路由,以便用户无法获取任何私人信息.但是用户可能会看到受保护的组件.
我认为没有办法隐藏用户100%安全的组件?