瀏覽代碼

Add shortcut route for post

sbkwgh 8 年之前
父節點
當前提交
435e86a7c0
共有 3 個文件被更改,包括 32 次插入1 次删除
  1. 1 1
      src/components/ThreadPost.vue
  2. 29 0
      src/components/routes/P.vue
  3. 2 0
      src/main.js

+ 1 - 1
src/components/ThreadPost.vue

@@ -87,7 +87,7 @@
 			return {
 				hover: false,
 				showShareModal: false,
-				postURL: `${location.origin}/thread/${post.Thread.slug}/${post.ThreadId}/${post.postNumber}`
+				postURL: `${location.origin}/p/${post.id}`
 			}
 		},
 		computed: {

+ 29 - 0
src/components/routes/P.vue

@@ -0,0 +1,29 @@
+<template>
+	<div class='route_container'>
+	</div>
+</template>
+
+<script>
+	import AjaxErrorHandler from '../../assets/js/errorHandler'
+	
+	export default {
+		name: 'P',
+		methods: {
+			redirect () {
+				let id = this.$route.params.id
+
+				this.axios
+					.get('/api/v1/post/' + id)
+					.then((res) => {
+						this.$router.push(
+							`/thread/${res.data.Thread.slug}/${res.data.Thread.id}/${res.data.postNumber}`
+						)
+					})
+					.catch(AjaxErrorHandler(this.$store))
+			}
+		},
+		beforeRouteEnter (to, from, next) {
+			next(vm => vm.redirect())
+		}
+	}
+</script>

+ 2 - 0
src/main.js

@@ -12,6 +12,7 @@ import App from './App'
 import store from './store/index'
 
 import Index from './components/routes/Index'
+import P from './components/routes/P'
 import Start from './components/routes/Start'
 import Thread from './components/routes/Thread'
 import ThreadNew from './components/routes/ThreadNew'
@@ -36,6 +37,7 @@ const router = new VueRouter({
 	routes: [
 		{ path: '/', redirect: '/category/all' },
 		{ path: '/category/:category', component: Index },
+		{ path: '/p/:id', component: P },
 		{ path: '/start', component: Start },
 		{ path: '/thread/:slug/:id', component: Thread },
 		{ path: '/thread/:slug/:id/:post_number', name: 'thread-post', component: Thread },