From fb5ba5a31417e3e134737497246de84e20e7d436 Mon Sep 17 00:00:00 2001 From: Chris Fritz Date: Sat, 9 Jul 2016 19:22:01 -0400 Subject: [PATCH 1/4] integrate pagejs --- package.json | 1 + src/components/VLink.vue | 14 +------------- src/main.js | 18 ++++++++---------- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 399fda7..b4abc6e 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "deploy": "surge --project . --domain vue-2-simple-routing-example.surge.sh" }, "dependencies": { + "page": "^1.7.1", "vue": "^2.0.0-beta.1" }, "devDependencies": { diff --git a/src/components/VLink.vue b/src/components/VLink.vue index 21d0bbb..598d303 100644 --- a/src/components/VLink.vue +++ b/src/components/VLink.vue @@ -2,7 +2,6 @@ @@ -17,18 +16,7 @@ }, computed: { isActive () { - return this.href === this.$root.currentRoute - } - }, - methods: { - go (event) { - event.preventDefault() - this.$root.currentRoute = this.href - window.history.pushState( - null, - routes[this.href], - this.href - ) + return this.href === window.location.pathname } } } diff --git a/src/main.js b/src/main.js index 861212b..da398b0 100644 --- a/src/main.js +++ b/src/main.js @@ -1,20 +1,18 @@ import Vue from 'vue' +import page from 'page' import routes from './routes' const app = new Vue({ el: '#app', data: { - currentRoute: window.location.pathname + ViewComponent: { render: h => h('div', 'loading...') } }, - render (h) { - const matchingView = routes[this.currentRoute] - const ViewComponent = matchingView - ? require('./pages/' + matchingView + '.vue').default - : require('./pages/404.vue').default - return h(ViewComponent) - } + render (h) { return h(this.ViewComponent) } }) -window.addEventListener('popstate', () => { - app.currentRoute = window.location.pathname +Object.keys(routes).forEach(route => { + const Component = require('./pages/' + routes[route] + '.vue').default + page(route, () => app.ViewComponent = Component) }) +page('*', () => app.ViewComponent = require('./pages/404.vue').default) +page() From 240f8a5cf87356fab9aa018fe90e3dd24191a742 Mon Sep 17 00:00:00 2001 From: Chris Fritz Date: Sat, 9 Jul 2016 19:32:49 -0400 Subject: [PATCH 2/4] add link to master branch --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ab61c4..6a3bdf2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Vue 2.0 Simple Routing Example -> A simple example of routing with Vue 2.0 without using vue-router. +> A simple example of routing with Vue 2.0 without using vue-router. This branch demonstrates integration of a 3rd-party router. For an example using the raw HTML5 History API, see the [master branch](https://github.com/chrisvfritz/vue-2.0-simple-routing-example/). ## Build Setup From c14c97868fb51c4d601c2f28e33f99de12508772 Mon Sep 17 00:00:00 2001 From: Chris Fritz Date: Sun, 10 Jul 2016 18:16:01 -0400 Subject: [PATCH 3/4] require VLink href prop --- src/components/VLink.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/VLink.vue b/src/components/VLink.vue index 598d303..9a8e885 100644 --- a/src/components/VLink.vue +++ b/src/components/VLink.vue @@ -12,7 +12,8 @@ export default { props: { - href: String + href: String, + required: true }, computed: { isActive () { From 15cbfcdfe29a23b4c723c588d582286f81ad7167 Mon Sep 17 00:00:00 2001 From: Chris Fritz Date: Tue, 20 Sep 2016 00:52:34 -0400 Subject: [PATCH 4/4] fix dynamic module requires --- src/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.js b/src/main.js index da398b0..39a79b4 100644 --- a/src/main.js +++ b/src/main.js @@ -11,8 +11,8 @@ const app = new Vue({ }) Object.keys(routes).forEach(route => { - const Component = require('./pages/' + routes[route] + '.vue').default + const Component = require('./pages/' + routes[route] + '.vue') page(route, () => app.ViewComponent = Component) }) -page('*', () => app.ViewComponent = require('./pages/404.vue').default) +page('*', () => app.ViewComponent = require('./pages/404.vue')) page()