Skip to content

Commit 6660cd2

Browse files
shentaoAkryum
authored andcommitted
feat: Add router tab (#735)
* First draft of implementation * Work on route filtering * Add route list column * Fix pane dragging * Extract diff into own method * Extract panes styling * Add nicer styling for redirect flag * Extract styling to common.styl * Fix highlight color of entries * Remove duplicate styling of entry elements * Make route list heading h3 * Change route list heading * Remove console.log * Fix closing tag in IndexRoute.vue * Implement toggle recording in router view list & simplyfy list of route changes * Add support for nested routes in router config * Split router from routes * Add fully working routes tab * Fix posible issue when there is no routes when routing is initialized. * Fix issue with not beeing allowed to select nested routes * feat: routing tab keyboard shortcut * feat: integrate routes history into framerate graph * fix: error if no corresponding metric * chore: add keep-alive in example * fix: abstract component error * fix(GroupDropdown): style + dark mode
1 parent 7f357e9 commit 6660cd2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1786
-44
lines changed

shells/dev/target/NativeTypes.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212

1313
<p>
1414
<button @click="sendComponent()">Vuex mutation</button>
15-
<button @click="createLargeArray()">Create large array</button>
15+
<button
16+
style="background: red; color: white;"
17+
@click="createLargeArray()"
18+
>
19+
Create large array
20+
</button>
1621
</p>
1722

1823
<h3>Set</h3>

shells/dev/target/Router.vue

Lines changed: 0 additions & 23 deletions
This file was deleted.

shells/dev/target/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import VuexObject from './VuexObject.vue'
77
import NativeTypes from './NativeTypes.vue'
88
import Events from './Events.vue'
99
import MyClass from './MyClass.js'
10-
import Router from './Router.vue'
1110
import router from './router'
11+
import Router from './router/Router.vue'
1212

1313
window.VUE_DEVTOOLS_CONFIG = {
1414
openInEditorHost: '/'
@@ -25,6 +25,12 @@ circular.self = circular
2525
new Vue({
2626
store,
2727
router,
28+
data: {
29+
obj: {
30+
items: items,
31+
circular
32+
}
33+
},
2834
render (h) {
2935
return h('div', null, [
3036
h(Counter),
@@ -35,12 +41,6 @@ new Vue({
3541
h(Router, { key: [] }),
3642
h(VuexObject)
3743
])
38-
},
39-
data: {
40-
obj: {
41-
items: items,
42-
circular
43-
}
4444
}
4545
}).$mount('#app')
4646

shells/dev/target/router.js

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,49 @@
11
import Vue from 'vue'
22
import VueRouter from 'vue-router'
3-
import Page1 from './Page1.vue'
4-
import Page2 from './Page2.vue'
3+
import RouteOne from './router/RouteOne.vue'
4+
import RouteTwo from './router/RouteTwo.vue'
5+
import RouteWithParams from './router/RouteWithParams.vue'
6+
import NamedRoute from './router/NamedRoute.vue'
7+
import RouteWithQuery from './router/RouteWithQuery.vue'
8+
import RouteWithBeforeEnter from './router/RouteWithBeforeEnter.vue'
9+
import RouteWithAlias from './router/RouteWithAlias.vue'
10+
import RouteWithProps from './router/RouteWithProps.vue'
11+
import ParentRoute from './router/ParentRoute.vue'
12+
import ChildRoute from './router/ChildRoute.vue'
513

614
Vue.use(VueRouter)
715

16+
const DynamicComponent = {
17+
render: (h) => h('div', 'Hello from dynamic component')
18+
}
19+
820
const routes = [
9-
{ path: '/', name: 'page1', component: Page1 },
10-
{ path: '/page2', name: 'page2', component: Page2 }
21+
{ path: '/route-one', component: RouteOne },
22+
{ path: '/route-two', component: RouteTwo },
23+
{ path: '/route-with-params/:username/:id', component: RouteWithParams },
24+
{ path: '/route-named', component: NamedRoute, name: 'NamedRoute' },
25+
{ path: '/route-with-query', component: RouteWithQuery },
26+
{ path: '/route-with-before-enter',
27+
component: RouteWithBeforeEnter,
28+
beforeEnter: (to, from, next) => {
29+
next()
30+
}},
31+
{ path: '/route-with-redirect', redirect: '/route-one' },
32+
{ path: '/route-with-alias', component: RouteWithAlias, alias: '/this-is-the-alias' },
33+
{ path: '/route-with-dynamic-component', component: DynamicComponent, props: true },
34+
{ path: '/route-with-props',
35+
component: RouteWithProps,
36+
props: {
37+
username: 'My Username',
38+
id: 99
39+
}},
40+
{ path: '/route-with-props-default', component: RouteWithProps },
41+
{ path: '/route-parent',
42+
component: ParentRoute,
43+
children: [
44+
{ path: '/route-child', component: ChildRoute }
45+
]
46+
}
1147
]
1248

1349
const router = new VueRouter({
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<h2>Child route</h2>
3+
</template>
4+
5+
<script>
6+
export default {
7+
8+
}
9+
</script>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<template>
2+
<div>
3+
<p>Hello named route</p>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
}
10+
</script>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<template>
2+
<div class="parent">
3+
<h2>Parent</h2>
4+
<router-view class="child"></router-view>
5+
</div>
6+
</template>
7+
8+
<script>
9+
export default {
10+
11+
}
12+
</script>

shells/dev/target/router/RouteOne.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<div>
3+
<p>Hello from route 1</p>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
10+
}
11+
</script>

shells/dev/target/router/RouteTwo.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<div>
3+
<p>Hello from route 2</p>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
10+
}
11+
</script>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<template>
2+
<div>
3+
<p>Hello from route with alias</p>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
}
10+
</script>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<template>
2+
<div>
3+
<p>Hello from before enter route</p>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
}
10+
</script>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<div>
3+
<p>Hello from route with params: Username: {{ $route.params.username }}, Id: {{ $route.params.id }}</p>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
10+
}
11+
</script>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<template>
2+
<div>
3+
<p>Hello from route with props: Username: {{ username }}, Id: {{ id }}</p>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
props: {
10+
username: {
11+
type: String,
12+
default: 'ms'
13+
},
14+
id: {
15+
type: Number,
16+
default: 33
17+
}
18+
}
19+
}
20+
</script>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<template>
2+
<div>
3+
<p>Hello from route with query: {{ $route.query }}</p>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
}
10+
</script>

shells/dev/target/router/Router.vue

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<template>
2+
<div>
3+
<p><router-link to="/route-one">Go to Route One</router-link></p>
4+
<p><router-link to="/route-two">Go to Route Two</router-link></p>
5+
<p><router-link to="/route-with-params/markussorg/5">Go to route with params</router-link></p>
6+
<p><router-link to="/route-named">Go to named route</router-link></p>
7+
<p><router-link to="/route-with-query?el=value&test=true">Go to route with query</router-link></p>
8+
<p><router-link to="/route-with-before-enter">Go to route with before enter</router-link></p>
9+
<p><router-link to="/route-with-redirect">Go to route with redirect</router-link></p>
10+
<p><router-link to="/this-is-the-alias">Go to route with alias</router-link></p>
11+
<p><router-link to="/route-with-dynamic-component">Go to route with dyn. component</router-link></p>
12+
<p><router-link to="/route-with-props">Go to route with props</router-link></p>
13+
<p><router-link to="/route-with-props-default">Go to route with props (default)</router-link></p>
14+
<p><router-link to="/route-parent">Go to route parent</router-link></p>
15+
<p><router-link to="/route-child">Go to route child</router-link></p>
16+
<keep-alive>
17+
<router-view />
18+
</keep-alive>
19+
<p><button @click="addRoutes">Add new routes</button></p>
20+
</div>
21+
</template>
22+
23+
<script>
24+
import RouteOne from './RouteOne.vue'
25+
26+
export default {
27+
methods: {
28+
addRoutes () {
29+
this.$router.addRoutes([
30+
{ path: '/new-route', component: RouteOne }
31+
])
32+
}
33+
}
34+
}
35+
</script>

src/backend/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { highlight, unHighlight, getInstanceOrVnodeRect } from './highlighter'
55
import { initVuexBackend } from './vuex'
66
import { initEventsBackend } from './events'
7+
import { initRouterBackend } from './router'
78
import { initPerfBackend } from './perf'
89
import { findRelatedComponent } from './utils'
910
import { stringify, classify, camelize, set, parse, getComponentName } from '../util'
@@ -121,6 +122,10 @@ function connect (Vue) {
121122
})
122123
}
123124

125+
hook.once('router:init', () => {
126+
initRouterBackend(hook.Vue, bridge, rootInstances)
127+
})
128+
124129
// events
125130
initEventsBackend(Vue, bridge)
126131

@@ -206,6 +211,7 @@ function scan () {
206211
return true
207212
}
208213
})
214+
hook.emit('router:init')
209215
flush()
210216
}
211217

@@ -340,7 +346,7 @@ function capture (instance, index, list) {
340346
captureCount++
341347
}
342348

343-
if (instance.$options && instance.$options.abstract) {
349+
if (instance.$options && instance.$options.abstract && instance._vnode.componentInstance) {
344350
instance = instance._vnode.componentInstance
345351
}
346352

src/backend/perf.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ function applyHooks (vm) {
9595
if (renderHook && renderHook.before) {
9696
// Render hook ends before one hook
9797
const metric = renderMetrics[renderHook.before]
98-
metric.end = time
99-
addComponentMetric(vm.$options, renderHook.before, metric.start, metric.end)
98+
if (metric) {
99+
metric.end = time
100+
addComponentMetric(vm.$options, renderHook.before, metric.start, metric.end)
101+
}
100102
}
101103

102104
// After

0 commit comments

Comments
 (0)