Skip to content

Commit 8971b85

Browse files
committed
Fix issue with not beeing allowed to select nested routes
1 parent 98af5c9 commit 8971b85

File tree

4 files changed

+59
-48
lines changed

4 files changed

+59
-48
lines changed

src/backend/router.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,40 @@ import { stringify } from '../util'
33
export function initRouterBackend (Vue, bridge, rootInstances) {
44
let recording = true
55

6+
const getSnapshot = () => {
7+
const routeChanges = []
8+
rootInstances.forEach(instance => {
9+
const router = instance._router
10+
if (router && router.options && router.options.routes) {
11+
routeChanges.push(...router.options.routes)
12+
}
13+
})
14+
return stringify({
15+
routeChanges
16+
})
17+
}
18+
19+
bridge.send('routes:init', getSnapshot())
20+
621
bridge.on('router:toggle-recording', enabled => {
722
recording = enabled
823
})
924

10-
for (let i = 0; i < rootInstances.length; i++) {
11-
const router = rootInstances[i]._router
25+
rootInstances.forEach(instance => {
26+
const router = instance._router
1227
if (router) {
1328
router.afterEach((to, from) => {
14-
if (recording) {
15-
bridge.send('router:changed', stringify({
16-
to,
17-
from,
18-
timestamp: Date.now()
19-
}))
20-
}
29+
if (!recording) return
30+
bridge.send('router:changed', stringify({
31+
to,
32+
from,
33+
timestamp: Date.now()
34+
}))
2135
})
2236
bridge.send('router:init', stringify({
2337
mode: router.mode
2438
}))
2539

26-
bridge.send('routes:init', stringify({
27-
routes: router.options.routes,
28-
mode: router.mode
29-
}))
30-
31-
if (router.options && router.options.routes) {
32-
router.options.routes.forEach(instance => {
33-
bridge.send('routes:changed', stringify(instance))
34-
})
35-
}
36-
3740
if (router.matcher && router.matcher.addRoutes) {
3841
const addRoutes = router.matcher.addRoutes
3942
router.matcher.addRoutes = function (routes) {
@@ -44,5 +47,5 @@ export function initRouterBackend (Vue, bridge, rootInstances) {
4447
}
4548
}
4649
}
47-
}
50+
})
4851
}

src/devtools/views/router/RouterMeta.vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<template>
22
<scroll-pane>
3-
<div v-if="activeRouteChange" slot="scroll" class="data-wrapper">
4-
<div class="data-fields">
5-
<data-field v-for="(value, key) of to" :key="key" :field="{ key, value }" :depth="0"></data-field>
6-
</div>
3+
<div v-if="activeRouteChange" slot="scroll">
4+
<state-inspector :state="{ from, to }" />
75
</div>
86
<div v-else slot="scroll" class="no-route-data">
97
No route transition selected
@@ -12,23 +10,27 @@
1210
</template>
1311

1412
<script>
15-
import DataField from 'components/DataField.vue'
13+
import StateInspector from 'components/StateInspector.vue'
14+
import ActionHeader from 'components/ActionHeader.vue'
1615
import ScrollPane from 'components/ScrollPane.vue'
1716
import { mapGetters } from 'vuex'
1817
import { UNDEFINED } from 'src/util'
1918
2019
export default {
2120
components: {
22-
DataField,
23-
ScrollPane
21+
ScrollPane,
22+
ActionHeader,
23+
StateInspector
2424
},
2525
computed: {
2626
...mapGetters('router', [
2727
'activeRouteChange'
2828
]),
2929
to () {
30-
// return this.activeRouteChange.to
3130
return this.sanitizeRouteData(this.activeRouteChange.to)
31+
},
32+
from () {
33+
return this.sanitizeRouteData(this.activeRouteChange.from)
3234
}
3335
},
3436
methods: {

src/devtools/views/routes/RoutesMeta.vue

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<template>
22
<scroll-pane>
3-
<div v-if="activeRouteChange" slot="scroll" class="data-wrapper">
4-
<div class="data-fields">
5-
<data-field v-for="(value, key) of to" :key="key" :field="{ key, value }" :depth="0"></data-field>
6-
</div>
3+
<div v-if="activeRouteChange" slot="scroll">
4+
<state-inspector :state="{ options }" />
75
</div>
86
<div v-else slot="scroll" class="no-route-data">
97
No route selected
@@ -12,21 +10,23 @@
1210
</template>
1311

1412
<script>
15-
import DataField from 'components/DataField.vue'
13+
import StateInspector from 'components/StateInspector.vue'
14+
import ActionHeader from 'components/ActionHeader.vue'
1615
import ScrollPane from 'components/ScrollPane.vue'
1716
import { mapGetters } from 'vuex'
1817
import { UNDEFINED } from 'src/util'
1918
2019
export default {
2120
components: {
22-
DataField,
23-
ScrollPane
21+
ScrollPane,
22+
ActionHeader,
23+
StateInspector
2424
},
2525
computed: {
2626
...mapGetters('routes', [
2727
'activeRouteChange'
2828
]),
29-
to () {
29+
options () {
3030
return this.sanitizeRouteData(this.activeRouteChange)
3131
}
3232
},
@@ -50,16 +50,16 @@ export default {
5050
}
5151
if (routeData.component) {
5252
const component = {}
53-
if (routeData.component.__file) {
54-
component.file = routeData.component.__file
55-
}
53+
// if (routeData.component.__file) {
54+
// component.file = routeData.component.__file
55+
// }
5656
if (routeData.component.template) {
5757
component.template = routeData.component.template
5858
}
5959
if (routeData.component.props) {
6060
component.props = routeData.component.props
6161
}
62-
if (component !== {}) {
62+
if (!this.isEmptyObject(component)) {
6363
data.component = component
6464
}
6565
}

src/devtools/views/routes/module.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,38 @@ const enabled = storage.get(ENABLED_KEY)
66
const state = {
77
enabled: enabled == null ? true : enabled,
88
hasRouter: false,
9-
instances: [],
109
routeChanges: [],
1110
inspectedIndex: -1,
1211
filter: ''
1312
}
1413

1514
const mutations = {
16-
'INIT' (state, payload) {
17-
state.instances = []
15+
INIT (state, payload) {
1816
state.inspectedIndex = -1
1917
state.hasRouter = true
20-
state.instances.push(payload)
18+
state.routeChanges = payload.routeChanges
2119
},
22-
'CHANGED' (state, payload) {
20+
CHANGED (state, payload) {
2321
state.routeChanges.push(payload)
2422
},
25-
'INSPECT' (state, index) {
23+
INSPECT (state, index) {
2624
state.inspectedIndex = index
2725
},
28-
'UPDATE_FILTER' (state, filter) {
26+
UPDATE_FILTER (state, filter) {
2927
state.filter = filter
3028
}
3129
}
3230

3331
const getters = {
3432
activeRouteChange: state => {
33+
if (typeof state.inspectedIndex === 'string') {
34+
const path = state.inspectedIndex.split('_')
35+
let obj = state.routeChanges[parseInt(path[0])]
36+
for (var i = 1, len = path.length; i < len; ++i) {
37+
obj = obj.children[parseInt(path[i])]
38+
}
39+
return obj
40+
}
3541
return state.routeChanges[state.inspectedIndex]
3642
},
3743
filteredRoutes: state => {

0 commit comments

Comments
 (0)