Skip to content

Commit

Permalink
🐛 Fix shareable URL 404 (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
stormwarning authored Apr 27, 2020
1 parent c33032f commit 1a85e98
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
29 changes: 29 additions & 0 deletions pages/_.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<template>
<div></div>
</template>

<script>
export default {
/**
* Parse the route params from the path and commit to store.
* @todo Add param validation and error page redirects.
*/
middleware({ params, store, redirect }) {
let { pathMatch } = params
let re = /mode\/([a-z]+)\/start\/([a-z0-9]+)\/end\/([a-z0-9]+)\/angle\/(\d+)/g
let [found] = [...pathMatch.matchAll(re)]
store.dispatch('changeMode', found[1])
store.dispatch('changeColor', { color: `#${found[2]}`, stop: 0 })
store.dispatch('changeColor', { color: `#${found[3]}`, stop: 1 })
store.dispatch('rotate', found[4])
},
/**
* Redirect to main page without changing browser history.
*/
created: function() {
this.$router.replace('/')
},
}
</script>
2 changes: 1 addition & 1 deletion pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default {
},
changeColorStop(color, stop) {
this.$store.commit('changeColor', { color, stop })
this.$store.dispatch('changeColor', { color, stop })
},
},
}
Expand Down
17 changes: 0 additions & 17 deletions pages/mode/_mode/start/_start/end/_end/angle/_deg.vue

This file was deleted.

10 changes: 7 additions & 3 deletions store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ export const state = () => ({
})

export const mutations = {
rotate(state, direction) {
CHANGE_ANGLE(state, direction) {
state.direction = direction
},

CHANGE_MODE(state, mode) {
state.colorMode = mode
},

changeColor(state, { color, stop }) {
CHANGE_STOP(state, { color, stop }) {
state.colorStops[stop].color.hex = color
},
}
Expand All @@ -39,6 +39,10 @@ export const actions = {
},

rotate({ commit }, direction) {
commit('rotate', direction)
commit('CHANGE_ANGLE', Number.parseInt(direction))
},

changeColor({ commit }, { color, stop }) {
commit('CHANGE_STOP', { color, stop })
},
}

0 comments on commit 1a85e98

Please sign in to comment.