Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add routing tab #322

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ build
tests_output
selenium-debug.log
TODOs.md
.vscode
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"lodash.debounce": "^4.0.6",
"lodash.groupby": "^4.6.0",
"vue": "^2.0.0",
"vue-router": "^2.3.0",
"vuex": "^2.0.0"
}
}
6 changes: 3 additions & 3 deletions shells/chrome/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module.exports = {
detector: './src/detector.js'
},
output: {
path: __dirname + '/build',
filename: '[name].js',
path: path.join(__dirname, '/build'),
filename: '[name].js'
},
resolve: {
alias
Expand All @@ -28,7 +28,7 @@ module.exports = {
rules: [
{
test: /\.js$/,
loader: 'buble-loader',
loader: 'buble-loader',
exclude: /node_modules|vue\/dist|vuex\/dist/,
options: bubleOptions
},
Expand Down
58 changes: 54 additions & 4 deletions shells/dev/target/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,72 @@ import Counter from './Counter.vue'
import Events from './Events.vue'
import MyClass from './MyClass.js'

let items = []
import IndexRoute from './router/IndexRoute.vue'
import RouteOne from './router/RouteOne.vue'
import RouteTwo from './router/RouteTwo.vue'
import RouteWithParams from './router/RouteWithParams.vue'
import NamedRoute from './router/NamedRoute.vue'
import RouteWithQuery from './router/RouteWithQuery.vue'
import RouteWithBeforeEnter from './router/RouteWithBeforeEnter.vue'
import RouteWithAlias from './router/RouteWithAlias.vue'
import RouteWithProps from './router/RouteWithProps.vue'
import ParentRoute from './router/ParentRoute.vue'
import ChildRoute from './router/ChildRoute.vue'

import VueRouter from 'vue-router'

Vue.use(VueRouter)

const DynamicComponent = {
template: '<div>Hello from dynamic component</div>'
}

const routes = [
{ path: '/route-one', component: RouteOne },
{ path: '/route-two', component: RouteTwo },
{ path: '/route-with-params/:username/:id', component: RouteWithParams },
{ path: '/route-named', component: NamedRoute, name: 'NamedRoute' },
{ path: '/route-with-query', component: RouteWithQuery },
{ path: '/route-with-before-enter', component: RouteWithBeforeEnter, beforeEnter: (to, from, next) => {
next()
}},
{ path: '/route-with-redirect', redirect: '/route-one' },
{ path: '/route-with-alias', component: RouteWithAlias, alias: '/this-is-the-alias' },
{ path: '/route-with-dynamic-component', component: DynamicComponent, props: true },
{ path: '/route-with-props', component: RouteWithProps, props: {
username: 'My Username',
id: 99
}},
{ path: '/route-with-props-default', component: RouteWithProps },
{ path: '/route-parent', component: ParentRoute,
children: [
{ path: '/route-child', component: ChildRoute }
]
}
]

const router = new VueRouter({
routes
})

const items = []
for (var i = 0; i < 100; i++) {
items.push({ id: i })
}

let circular = {}
const circular = {}
circular.self = circular

new Vue({
store,
router,
render (h) {
return h('div', null, [
h(Counter),
h(Target, {props:{msg: 'hi', ins: new MyClass()}}),
h(Target, {props: {msg: 'hi', ins: new MyClass()}}),
h(Other),
h(Events)
h(Events),
h(IndexRoute)
])
},
data: {
Expand Down
9 changes: 9 additions & 0 deletions shells/dev/target/router/ChildRoute.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<h2>Child route</h2>
</template>

<script>
export default {
}
</script>
33 changes: 33 additions & 0 deletions shells/dev/target/router/IndexRoute.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<template>
<div>
<p><router-link to="/route-one">Go to Route One</router-link></p>
<p><router-link to="/route-two">Go to Route Two</router-link></p>
<p><router-link to="/route-with-params/markussorg/5">Go to route with params</router-link></p>
<p><router-link to="/route-named">Go to named route</router-link></p>
<p><router-link to="/route-with-query?el=value&test=true">Go to route with query</router-link></p>
<p><router-link to="/route-with-before-enter">Go to route with before enter</router-link></p>
<p><router-link to="/route-with-redirect">Go to route with redirect</router-link></p>
<p><router-link to="/this-is-the-alias">Go to route with alias</router-link></p>
<p><router-link to="/route-with-dynamic-component">Go to route with dyn. component</router-link></p>
<p><router-link to="/route-with-props">Go to route with props</router-link></p>
<p><router-link to="/route-with-props-default">Go to route with props (default)</router-link></p>
<p><router-link to="/route-parent">Go to route parent</router-link></p>
<p><router-link to="/route-child">Go to route child</router-link></p>
<router-view></router-view>
<p><button @click="addRoutes">Add new routes</button></p>
</div>
</template>

<script>
import RouteOne from './RouteOne.vue'

export default {
methods: {
addRoutes () {
this.$router.addRoutes([
{ path: '/new-route', component: RouteOne }
])
}
}
}
</script>
10 changes: 10 additions & 0 deletions shells/dev/target/router/NamedRoute.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<div>
<p>Hello named route</p>
</div>
</template>

<script>
export default {
}
</script>
12 changes: 12 additions & 0 deletions shells/dev/target/router/ParentRoute.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<div class="parent">
<h2>Parent</h2>
<router-view class="child"></router-view>
</div>
</template>

<script>
export default {

}
</script>
11 changes: 11 additions & 0 deletions shells/dev/target/router/RouteOne.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div>
<p>Hello from route 1</p>
</div>
</template>

<script>
export default {
}
</script>
11 changes: 11 additions & 0 deletions shells/dev/target/router/RouteTwo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div>
<p>Hello from route 2</p>
</div>
</template>

<script>
export default {
}
</script>
10 changes: 10 additions & 0 deletions shells/dev/target/router/RouteWithAlias.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<div>
<p>Hello from route with alias</p>
</div>
</template>

<script>
export default {
}
</script>
10 changes: 10 additions & 0 deletions shells/dev/target/router/RouteWithBeforeEnter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<div>
<p>Hello from before enter route</p>
</div>
</template>

<script>
export default {
}
</script>
11 changes: 11 additions & 0 deletions shells/dev/target/router/RouteWithParams.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div>
<p>Hello from route with params: Username: {{ $route.params.username }}, Id: {{ $route.params.id }}</p>
</div>
</template>

<script>
export default {

}
</script>
20 changes: 20 additions & 0 deletions shells/dev/target/router/RouteWithProps.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<template>
<div>
<p>Hello from route with props: Username: {{ username }}, Id: {{ id }}</p>
</div>
</template>

<script>
export default {
props: {
username: {
type: String,
default: 'ms'
},
id: {
type: Number,
default: 33
}
}
}
</script>
10 changes: 10 additions & 0 deletions shells/dev/target/router/RouteWithQuery.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<div>
<p>Hello from route with query: {{ $route.query }}</p>
</div>
</template>

<script>
export default {
}
</script>
4 changes: 4 additions & 0 deletions src/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { highlight, unHighlight, getInstanceRect } from './highlighter'
import { initVuexBackend } from './vuex'
import { initEventsBackend } from './events'
import { initRouterBackend } from './router'
import { stringify, classify, camelize } from '../util'
import path from 'path'

Expand Down Expand Up @@ -95,6 +96,9 @@ function connect () {
bridge.send('ready', hook.Vue.version)
console.log('[vue-devtools] Ready. Detected Vue v' + hook.Vue.version)
scan()

// router
initRouterBackend(hook.Vue, bridge, rootInstances)
}

/**
Expand Down
51 changes: 51 additions & 0 deletions src/backend/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { stringify } from '../util'

export function initRouterBackend (Vue, bridge, rootInstances) {
let recording = true

const getSnapshot = () => {
const routeChanges = []
rootInstances.forEach(instance => {
const router = instance._router
if (router && router.options && router.options.routes) {
routeChanges.push(...router.options.routes)
}
})
return stringify({
routeChanges
})
}

bridge.send('routes:init', getSnapshot())

bridge.on('router:toggle-recording', enabled => {
recording = enabled
})

rootInstances.forEach(instance => {
const router = instance._router
if (router) {
router.afterEach((to, from) => {
if (!recording) return
bridge.send('router:changed', stringify({
to,
from,
timestamp: Date.now()
}))
})
bridge.send('router:init', stringify({
mode: router.mode
}))

if (router.matcher && router.matcher.addRoutes) {
const addRoutes = router.matcher.addRoutes
router.matcher.addRoutes = function (routes) {
routes.forEach((item) => {
bridge.send('routes:changed', stringify(item))
})
addRoutes.call(this, routes)
}
}
}
})
}
20 changes: 19 additions & 1 deletion src/devtools/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@
<span class="pane-name">Events</span>
<span class="event-count" v-if="newEventCount > 0">{{ newEventCount }}</span>
</a>
<a class="button router"
:class="{ active: tab === 'router' }"
@click="switchTab('router')"
title="Switch to Router">
<i class="material-icons">directions</i>
<span class="pane-name">Router</span>
</a>
<a class="button router"
:class="{ active: tab === 'routes' }"
@click="switchTab('routes')"
title="Switch to Routes">
<i class="material-icons">book</i>
<span class="pane-name">Routes</span>
</a>
<a class="button refresh"
@click="refresh"
title="Force Refresh">
Expand All @@ -47,6 +61,8 @@
import ComponentsTab from './views/components/ComponentsTab.vue'
import EventsTab from './views/events/EventsTab.vue'
import VuexTab from './views/vuex/VuexTab.vue'
import RouterTab from './views/router/RouterTab.vue'
import RoutesTab from './views/routes/RoutesTab.vue'

import { mapState } from 'vuex'

Expand All @@ -62,7 +78,9 @@ export default {
components: {
components: ComponentsTab,
vuex: VuexTab,
events: EventsTab
events: EventsTab,
router: RouterTab,
routes: RoutesTab
},
computed: mapState({
message: state => state.message,
Expand Down
Loading