forked from oarepo/vue-query-synchronizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
58 lines (50 loc) · 1.64 KB
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from './Home.vue'
import { query } from '@oarepo/vue-query-synchronizer'
Vue.use(VueRouter)
const routes = [
{
path: '/',
name: 'home',
props: query(
[
// simple form, string parameter
'search',
// object form
{ name: 'search2', debounce: 1000 },
// number with the default value of 10
'number:num:10',
// checkbox (bool field) with a custom debounce of 1ms
'1:bool:check',
// array field, without debounce (the same as 0:array:option)
':array:option'
],
{
another: 'property passed directly to the component'
},
{
onInit: (props) => {
console.log('onInit', props)
props.filter(x => x.name === 'search')[0].defaultValue =
window.localStorage.getItem('searchDefaultValue')
return props
},
onLoad: (params) => {
console.log('onLoad', params)
return params
},
onChange: (query, queryValues) => {
window.localStorage.setItem('searchDefaultValue', queryValues.search || '')
console.log('onChange', query, queryValues)
}
}),
component: Home
}
]
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
export default router