小编off*_*ffz的帖子

Vue Router:保留查询参数并为子节点使用相同的视图

我正在用Vue重写现有的Angular 1应用程序.

该应用程序总是需要由用户进行身份验证locale,idtoken进入任何意见之前.尊重API的约定,我token在主要父路由中指定了一个查询参数.

来自现有的Angular的UI路由器实现,我认为这是要走的路:

// main.js
new Vue({
  el: '#app',
  router,
  store,
  template: '<router-view name="main"></router-view>'
})

// router.js
const router = new Router({
  mode: 'history',
  routes: [
    {
      name: 'start',
      path : '/:locale/:id', // /:locale/:id?token didn't work
      query: {
        token: null
      },
      beforeEnter (to, from, next) {
        // 1. Get data from API via locale, id and token
        // 2. Update store with user data
      },
      components: {
        main: startComponent …
Run Code Online (Sandbox Code Playgroud)

vue-router vuejs2

7
推荐指数
1
解决办法
5769
查看次数

标签 统计

vue-router ×1

vuejs2 ×1