Save previous route name, if none found push route highscore.

This commit is contained in:
2020-10-11 13:32:44 +02:00
committed by KevinMidboe
parent a59f1e2b17
commit 8ef1a2dd88

View File

@@ -3,9 +3,9 @@
<h1>Vinlottis highscore</h1>
<div class="backdrop">
<router-link to="/highscore">
<h3 class="vin-link go-back">Tilbake til topplisten</h3>
</router-link>
<a @click="navigateBack" @keydown.enter="navigateBack">
<span class="vin-link navigate-back">Tilbake til {{ previousRoute.name }}</span>
</a>
<section v-if="winner">
<h2 class="name">{{ winner.name }}</h2>
@@ -53,19 +53,23 @@ import { getWinnerByName } from "@/api";
import { humanReadableDate, daysAgo } from "@/utils";
export default {
props: {
winnerObject: {
type: Object,
required: false,
default: undefined
}
},
data() {
return {
winner: undefined,
error: undefined
error: undefined,
previousRoute: {
default: true,
name: "topplisten",
path: "/highscore"
}
}
},
beforeRouteEnter(to, from, next) {
next(vm => {
if (from.name !== null)
vm.previousRoute = from
})
},
computed: {
numberOfWins() {
return this.winner.highscore.length
@@ -79,7 +83,11 @@ export default {
},
methods: {
setWinner(winner) {
this.winner = winner
this.winner = {
name: winner.name,
highscore: [],
...winner
}
this.winningColors = this.findWinningColors()
},
smallerWineImage(image) {
@@ -103,6 +111,13 @@ export default {
const timestamp = new Date(date).getTime();
return `/history/${timestamp}`
},
navigateBack() {
if (this.previousRoute.default) {
this.$router.push({ path: this.previousRoute.path });
} else {
this.$router.go(-1);
}
},
humanReadableDate: humanReadableDate,
daysAgo: daysAgo
}