vue刷新跳转首页

一刷新就跳首页

main.js

const router = new VueRouter({
  history: false,
  hashbang: true,
  routes
})

router.js

const routers = [
    {
      path:'/login',
      component:login,
    },
    {
      path: '/welcome',
      component: welcome,
    },
    {
      path: '/test',
      component: test,
    },
    {
      path: '/',
      component: Home,
      children: [
        { path: '/clueFilter', component: clueFilter, name: '首页'},
        { path: '/myTags', component: myTags, name: '我的'},
      ]
    },
    {
      path: '/',
      component: Home,
      children: [
        { path: '/statistics',component: statistics, name: '下载记录'},
        { path: '/tableHistory', component:tableHistory,name: '已下载'},
        { path: '', name: '业务分析',permissions:'vip'}
      ]
    }
  ]
  

app.vue

  export default {
    name: 'app',
    components: {
    },
    created: function () {
      this.$router.push('/login')
    }
  }

不管在哪页刷新,就一直跳转login页,是否我设置初始页面的方式有问题?

阅读 14.6k
4 个回答

仔细翻阅官方文档。。用redirect指向首页,而不是直接push。

你这段代码去掉试试。
this.$router.push('/login')

新手上路,请多包涵

你的 app.vue 在 created 方法里就是这样写的,一旦 app 创建就跳转到 /login 页面。

不知道你的业务逻辑是怎样的,但大体上思路是在跳转 /login 的地方做判断,不要直接跳。

 export default {
    name: 'app',
    components: {
    },
    created: function () {
      this.$router.push('/login') // 注意! 你这个代码的意思就是每次刷新的时候进入'/login',去掉就可以了
    }
 }
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题