|
| 1 | +import VueRouter from '../index' |
| 2 | +import { Route } from '../index' |
| 3 | + |
| 4 | +const router = new VueRouter() |
| 5 | +const route: Route = router.currentRoute |
| 6 | + |
| 7 | +const stringQuery: string | null | (string | null)[] = route.query['stringParam'] |
| 8 | +if (typeof stringQuery === 'string') { |
| 9 | + console.log(stringQuery.toLowerCase()) |
| 10 | +} |
| 11 | + |
| 12 | +const nullQuery: string | null | (string | null)[] = route.query['paramWithoutValue'] |
| 13 | +if (nullQuery === null) { |
| 14 | + console.log('Parameter exists but has no value') |
| 15 | +} |
| 16 | + |
| 17 | +const arrayQuery: string | null | (string | null)[] = route.query['arrayParam'] |
| 18 | +if (Array.isArray(arrayQuery)) { |
| 19 | + arrayQuery.forEach(value => { |
| 20 | + if (value === null) { |
| 21 | + console.log('Array contains null value') |
| 22 | + } else { |
| 23 | + console.log(value.toLowerCase()) |
| 24 | + } |
| 25 | + }) |
| 26 | +} |
| 27 | + |
| 28 | +router.push({ |
| 29 | + path: '/test', |
| 30 | + query: { |
| 31 | + string: 'value', // string value |
| 32 | + empty: null, // null value |
| 33 | + array: ['value1', 'value2'], // array of strings |
| 34 | + mixedArray: ['value', null], // array with null |
| 35 | + noValue: null // parameter without value |
| 36 | + } |
| 37 | +}) |
| 38 | + |
| 39 | +const routeWithQueries: Route = { |
| 40 | + path: '/test', |
| 41 | + name: null, |
| 42 | + hash: '', |
| 43 | + query: { |
| 44 | + param1: 'string', // string value |
| 45 | + param2: null, // null value |
| 46 | + param3: ['val1', 'val2'], // array of strings |
| 47 | + param4: ['val', null], // array with null |
| 48 | + param5: null // parameter without value |
| 49 | + }, |
| 50 | + params: {}, |
| 51 | + fullPath: '/test', |
| 52 | + matched: [] |
| 53 | +} |
0 commit comments