ソースを参照

ua redirect add white-list

hare8999@163.com 2 年 前
コミット
aa5a13982e
4 ファイル変更7 行追加9 行削除
  1. 1 6
      src/App.vue
  2. 4 1
      src/permission.js
  3. 1 1
      src/router/index.js
  4. 1 1
      src/views/questioncenter/question-preview.vue

+ 1 - 6
src/App.vue

@@ -5,14 +5,9 @@
 </template>
 
 <script>
-import { uaredirect } from '@/utils/uaredirect.js'
 
 export default {
-  name: 'App',
-  created: function() {
-    console.log('Created uaredirect')
-    uaredirect()
-  }
+  name: 'App'
 }
 </script>
 <style>

+ 4 - 1
src/permission.js

@@ -3,12 +3,14 @@ import store from './store'
 import NProgress from 'nprogress'
 import 'nprogress/nprogress.css'
 import auth from '@/utils/auth'
+import { uaredirect } from '@/utils/uaredirect'
 
 NProgress.configure({
   showSpinner: false
 })
 
-const whiteList = ['/login', '/auth-redirect', '/bind', '/register']
+const whiteList = ['/login', '/auth-redirect', '/bind', '/register', '/question/preview']
+const uaWhiteList = ['/question/preview']
 
 router.beforeEach((to, from, next) => {
   NProgress.start()
@@ -54,6 +56,7 @@ router.beforeEach((to, from, next) => {
     // 没有token
     if (whiteList.indexOf(to.path) !== -1) {
       // 在免登录白名单,直接进入
+      if (!uaWhiteList.includes(to.path)) uaredirect()
       next()
     } else {
       // next()

+ 1 - 1
src/router/index.js

@@ -56,7 +56,7 @@ export const constantRoutes = [{
     hidden: true
   },
   {
-    path: '/question/preview/:id',
+    path: '/question/preview',
     hidden: true,
     component: (resolve) => require(['@/views/questioncenter/question-preview'], resolve),
     meta: {

+ 1 - 1
src/views/questioncenter/question-preview.vue

@@ -22,7 +22,7 @@ export default {
   },
   computed: {
     questionId() {
-      return this.$route.params.id || 0
+      return this.$route.query?.id || this.$route.query?.questionId || 0
     },
     questionOptions() {
       return {