search

Home  >  Q&A  >  body text

javascript - vue refreshes and jumps to the home page

Jump to homepage as soon as refreshed

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')
    }
  }

No matter which page is refreshed, it always jumps to the login page. Is there something wrong with the way I set the initial page?

曾经蜡笔没有小新曾经蜡笔没有小新2747 days ago523

reply all(4)I'll reply

  • 某草草

    某草草2017-05-19 10:37:03

    Read the official documentation carefully. . Use redirect to point to the homepage instead of pushing directly.

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-19 10:37:03

    Try removing this code.
    this.$router.push('/login')

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-19 10:37:03

    Your app.vue is written like this in the created method. Once the app is created, it will jump to the /login page.

    I don’t know what your business logic is, but the general idea is to make a judgment where you jump to /login, don’t jump directly.

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-19 10:37:03

     export default {
        name: 'app',
        components: {
        },
        created: function () {
          this.$router.push('/login') // 注意! 你这个代码的意思就是每次刷新的时候进入'/login',去掉就可以了
        }
     }

    reply
    0
  • Cancelreply