router.js 881 Bytes
/*
 * @Date: 2022-10-28 14:34:22
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2022-11-01 13:27:09
 * @FilePath: /swx/src/stores/router.js
 * @Description: 缓存路由信息
 */
import { defineStore } from 'pinia'

/**
 * @description 路由回跳信息(用于授权完成后的返回)
 * - authRedirect.saveCurrentPagePath 会写入 url
 * - authRedirect.returnToOriginalPage 会消费并清空 url
 */
export const routerStore = defineStore('router', {
  state: () => {
    return {
      url: ''
    }
  },
  actions: {
    /**
     * @description 记录回跳路径
     * @param {string} path 页面路径(可带 query)
     * @returns {void} 无返回值
     */
    add(path) {
      this.url = path
    },
    /**
     * @description 清空回跳路径
     * @returns {void} 无返回值
     */
    remove() {
      this.url = ''
    }
  }
})