diff --git a/package.json b/package.json
index 7084826..93d7882 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,8 @@
"dependencies": {
"bulma": "^0.6.1",
"express": "^4.16.2",
- "vue": "^2.5.6"
+ "vue": "^2.5.6",
+ "vue-router": "^3.0.1"
},
"devDependencies": {
"babel-core": "^6.26.0",
diff --git a/src/app.js b/src/app.js
index ff9ef0d..c6c9c63 100644
--- a/src/app.js
+++ b/src/app.js
@@ -1,7 +1,9 @@
import Vue from 'vue'
import AppLayout from './theme/Layout.vue'
+import router from './router'
const app = new Vue({
+ router,
// render is a Vuejs function that will return an elements
// This is equivalent to template: ''
render: h => h(AppLayout)
@@ -10,4 +12,4 @@ const app = new Vue({
// ...AppLayout //this part didn't work. I don't know why but
})
-export { app }
+export { app, router }
diff --git a/src/router.js b/src/router.js
new file mode 100644
index 0000000..a1b928b
--- /dev/null
+++ b/src/router.js
@@ -0,0 +1,50 @@
+import Vue from 'vue'
+import VueRouter from 'vue-router'
+import Category from './theme/Category.vue'
+import Login from './theme/Login.vue'
+import NotFound from './theme/NotFound.vue'
+
+// Here we are breaking these up into Async components because if you are only
+// visiting one site you don't need all the other components loaded
+// WE ARE REVERTING THIS BECAUSE IT IS GREAT FOR CLIENT SIDE rendering
+// BUT WE ARE GOING TO DO "SERVER SIDE RENDERING" BY THE END OF THIS
+// const Category = () => System.import('./theme/Category.vue')
+// const Login = () => System.import('./theme/Login.vue')
+// const NotFound = () => System.import('./theme/NotFound.vue')
+
+Vue.use(VueRouter)
+
+const router = new VueRouter({
+ // We can use the history API in modern Browsers to avoid seeing # in the urlParams
+ mode: 'history',
+ // We can change the default router-link-active class for active routes to
+ // a class that our CSS library can use
+ linkActiveClass: 'is-active',
+ // Scroll Behavior is essentionally a method that accepts to path, from path
+ // and the scroll position that the page was in
+ // Here we are seeting the y position to 0 so that we scroll to the top of the page
+ scrollBehavior: (to, from, savedPosition) => ({ y: 0 }),
+ // In the routes array we can link Routes with Components
+ routes: [
+ {
+ path: '/category/:id', // Here we are going to use dynamic routing
+ name: 'category', // this is a naming of the rule it allows us to pass json objects into the router-link to attribute
+ component: Category
+ },
+ {
+ path: '/login',
+ component: Login
+ },
+ {
+ path: '/',
+ redirect: '/category/front-end'
+ },
+ {
+ path: '*',
+ component: NotFound
+ }
+ ]
+}
+)
+
+export default router
diff --git a/src/theme/AppHeader.vue b/src/theme/AppHeader.vue
index c3ddc36..2a61eba 100644
--- a/src/theme/AppHeader.vue
+++ b/src/theme/AppHeader.vue
@@ -1,10 +1,23 @@