JSFiddle - React, Tailwind, and code Playground

by Eduardo San Martin Morote

HTML

<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<div id="app">
  <h1>Hello App!</h1>
  <p>{{url}}</p>
  <p>
    <router-link to="/foo">Go to Foo</router-link>
    <router-link to="/bar">Go to Bar</router-link>
    <button @click="pushUrl">Push Url</button>
  </p>
  <router-view></router-view>
  <pre>{{$route.query}}</pre>
</div>

JavaScript

const Foo = { template: '<div>foo</div>' }
const Bar = { template: '<div>bar</div>' }
const data = {
  url: location.href
}

const routes = [
  { path: '/foo', component: Foo },
  { path: '/bar', component: Bar }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  data.url = location.href
  next()
})

const app = new Vue({
  data,
  methods: {
    pushUrl () {
      router.push({ path: '/foo', query: { x: [1,2] }})
    }
  },
  router
}).$mount('#app')