'vue-element-admin this.$router.push can't work
I want to use vue-element-admin to make a button for registering, so I copy the file folder which name is src/view/login
,and rename it as register
,then in the file folder which name is src/router/index
add the code block as follow:
{
path: '/regist',
component: () => import('@/views/regist/index'),
hidden: true
}
then in the file which name is src/views/login/index.vue
, I add a button as follow:
<el-button :loading="loading" type="primary" style="width:100%;margin:0 0 30px;" @click="handleRegist">New?Register</el-button>
the handleRegist
as follow:
handleRegist(){
this.$router.push({path: "/regist"});
console.log("can't get the regist page")
}
I expected when I click the registered button, then get a regist page. however, when I click that button and it still show the login page.
and after clicking the registered button, the router path is
http://localhost:9527/#/login?redirect=%2Fregist
which I expect it is http://localhost:9527/#/regist
the description of the problem is end. and I have try to do something to solve this problem:
file path:src/permission.js
,I add the code block in router.beforeEach(async(to, from, next) =>
as follow :
if(to.path === '/register'){
next()
}
but I get the same problem as above.
what should I do to get the register page,please help me! Thank you!
Solution 1:[1]
what happens if you use this?
this.$router.push('/regist')
what happens if you use this method to push to a different view, like '/' ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | j-bill |