Convert Figma logo to code with AI

chrisvfritz logovue-2.0-simple-routing-example

A simple example of routing with Vue 2.0 without using vue-router.

1,648
801
1,648
7

Top Related Projects

🚦 The official router for Vue 2

9,679

A full-featured Webpack + vue-loader setup with hot reload, linting, testing & css extraction.

29,731

🛠️ webpack-based tooling for Vue.js Development

57,828

The Intuitive Vue Framework.

26,678

Quasar Framework - Build high-performance VueJS user interfaces in record time

22,788

📝 Minimalistic Vue-powered static site generator

Quick Overview

The vue-2.0-simple-routing-example is a GitHub repository that demonstrates a basic implementation of client-side routing in Vue.js 2.0 without using vue-router. It showcases how to create a simple single-page application (SPA) with navigation between different views using Vue's component system and JavaScript's History API.

Pros

  • Provides a lightweight alternative to vue-router for simple routing needs
  • Demonstrates Vue.js core concepts and component-based architecture
  • Easy to understand and implement for beginners
  • Offers a foundation for building custom routing solutions

Cons

  • Limited functionality compared to vue-router
  • May not scale well for larger applications with complex routing requirements
  • Lacks advanced features like nested routes and route guards
  • Requires manual management of route changes and history

Code Examples

  1. Defining routes:
const routes = {
  '/': Home,
  '/about': About
}
  1. Implementing the router view component:
const app = new Vue({
  el: '#app',
  data: {
    currentRoute: window.location.pathname
  },
  computed: {
    ViewComponent () {
      return routes[this.currentRoute] || NotFound
    }
  },
  render (h) { return h(this.ViewComponent) }
})
  1. Handling navigation:
window.addEventListener('popstate', () => {
  app.currentRoute = window.location.pathname
})

Getting Started

  1. Clone the repository:

    git clone https://github.com/chrisvfritz/vue-2.0-simple-routing-example.git
    
  2. Navigate to the project directory:

    cd vue-2.0-simple-routing-example
    
  3. Open index.html in a web browser to see the example in action.

  4. Explore the app.js file to understand the routing implementation.

Competitor Comparisons

🚦 The official router for Vue 2

Pros of vue-router

  • More feature-rich and robust routing solution
  • Supports nested routes and route parameters
  • Integrates seamlessly with Vue.js ecosystem

Cons of vue-router

  • Steeper learning curve for beginners
  • Adds additional complexity to smaller projects
  • Requires more setup and configuration

Code Comparison

vue-2.0-simple-routing-example:

const routes = {
  '/': Home,
  '/about': About
}

new Vue({
  el: '#app',
  data: {
    currentRoute: window.location.pathname
  },
  computed: {
    ViewComponent () {
      return routes[this.currentRoute] || NotFound
    }
  },
  render (h) { return h(this.ViewComponent) }
})

vue-router:

const router = new VueRouter({
  routes: [
    { path: '/', component: Home },
    { path: '/about', component: About }
  ]
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')

The vue-2.0-simple-routing-example provides a basic routing solution using a simple object to map routes to components. It's lightweight and easy to understand but lacks advanced features.

vue-router offers a more powerful and flexible routing system with support for nested routes, navigation guards, and route parameters. It integrates well with Vue.js and provides a more scalable solution for larger applications.

9,679

A full-featured Webpack + vue-loader setup with hot reload, linting, testing & css extraction.

Pros of webpack

  • More comprehensive build setup with advanced features like hot-reloading and code-splitting
  • Includes ESLint for code quality and error checking
  • Better suited for larger, production-ready applications

Cons of webpack

  • More complex configuration and setup process
  • Steeper learning curve for beginners
  • Potentially overkill for small, simple projects

Code Comparison

vue-2.0-simple-routing-example:

const routes = {
  '/': Home,
  '/about': About
}

new Vue({
  el: '#app',
  data: {
    currentRoute: window.location.pathname
  },
  computed: {
    ViewComponent () {
      return routes[this.currentRoute] || NotFound
    }
  },
  render (h) { return h(this.ViewComponent) }
})

webpack:

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Home
    },
    {
      path: '/about',
      name: 'About',
      component: About
    }
  ]
})

The vue-2.0-simple-routing-example uses a basic object for routing, while webpack utilizes vue-router for more robust routing capabilities. The webpack template provides a more structured and scalable approach to routing, which is beneficial for larger applications.

29,731

🛠️ webpack-based tooling for Vue.js Development

Pros of vue-cli

  • Provides a full-featured development environment with built-in tools and configurations
  • Offers a wide range of official and community-maintained plugins for easy project customization
  • Supports modern web development practices like hot-reloading and code-splitting out of the box

Cons of vue-cli

  • May be overkill for simple projects or learning purposes
  • Requires additional setup and configuration compared to a basic Vue.js application
  • Can be more challenging for beginners to understand the underlying structure

Code Comparison

vue-2.0-simple-routing-example:

const app = new Vue({
  el: '#app',
  data: {
    currentRoute: window.location.pathname
  },
  computed: {
    ViewComponent () {
      return routes[this.currentRoute] || NotFound
    }
  },
  render (h) { return h(this.ViewComponent) }
})

vue-cli (generated project):

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

The vue-2.0-simple-routing-example demonstrates a basic routing implementation, while vue-cli provides a more structured approach with separate router and store modules. Vue CLI offers a more scalable and maintainable project structure for larger applications, but may be more complex for simple use cases.

57,828

The Intuitive Vue Framework.

Pros of Nuxt

  • Full-featured framework with built-in routing, state management, and server-side rendering
  • Automatic code splitting and optimized performance out of the box
  • Rich ecosystem with extensive plugins and modules

Cons of Nuxt

  • Steeper learning curve due to additional concepts and conventions
  • Potentially overkill for simple applications or prototypes
  • Less flexibility in custom routing configurations

Code Comparison

vue-2.0-simple-routing-example:

const routes = {
  '/': Home,
  '/about': About
}

new Vue({
  el: '#app',
  data: {
    currentRoute: window.location.pathname
  },
  computed: {
    ViewComponent () {
      return routes[this.currentRoute] || NotFound
    }
  },
  render (h) { return h(this.ViewComponent) }
})

Nuxt:

// pages/index.vue
export default {
  name: 'HomePage'
}

// pages/about.vue
export default {
  name: 'AboutPage'
}

// Routing is automatically handled based on file structure

The vue-2.0-simple-routing-example demonstrates a basic routing implementation using Vue.js, while Nuxt provides a more structured approach with file-based routing. Nuxt simplifies the routing process by automatically generating routes based on the file structure in the pages directory, eliminating the need for manual route configuration in most cases.

26,678

Quasar Framework - Build high-performance VueJS user interfaces in record time

Pros of Quasar

  • Comprehensive UI framework with a large set of pre-built components
  • Cross-platform development support (web, mobile, and desktop)
  • Active community and regular updates

Cons of Quasar

  • Steeper learning curve due to its extensive feature set
  • Potentially larger bundle size for simple applications
  • More opinionated structure, which may limit flexibility for some projects

Code Comparison

vue-2.0-simple-routing-example:

const routes = {
  '/': Home,
  '/about': About
}

new Vue({
  el: '#app',
  data: {
    currentRoute: window.location.pathname
  },
  computed: {
    ViewComponent () {
      return routes[this.currentRoute] || NotFound
    }
  },
  render (h) { return h(this.ViewComponent) }
})

Quasar:

const routes = [
  {
    path: '/',
    component: () => import('layouts/MainLayout.vue'),
    children: [
      { path: '', component: () => import('pages/Index.vue') },
      { path: 'about', component: () => import('pages/About.vue') }
    ]
  }
]

export default routes

The vue-2.0-simple-routing-example demonstrates a basic routing setup using Vue.js, while Quasar uses Vue Router with a more structured approach, including layout components and lazy-loading for route components.

22,788

📝 Minimalistic Vue-powered static site generator

Pros of VuePress

  • Built-in static site generation capabilities
  • Optimized for technical documentation with features like automatic sidebar generation
  • Integrated search functionality out of the box

Cons of VuePress

  • More complex setup compared to the simple routing example
  • Potentially overkill for small projects or simple single-page applications
  • Steeper learning curve for developers new to static site generators

Code Comparison

vue-2.0-simple-routing-example:

const routes = {
  '/': Home,
  '/about': About
}

new Vue({
  el: '#app',
  data: {
    currentRoute: window.location.pathname
  },
  computed: {
    ViewComponent () {
      return routes[this.currentRoute] || NotFound
    }
  },
  render (h) { return h(this.ViewComponent) }
})

VuePress:

module.exports = {
  title: 'Hello VuePress',
  description: 'Just playing around',
  themeConfig: {
    sidebar: [
      '/',
      '/about/'
    ]
  }
}

The vue-2.0-simple-routing-example demonstrates a basic client-side routing implementation, while VuePress uses a configuration-based approach for generating static sites with built-in routing and theming capabilities.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Vue 2.0 Simple Routing Example

A simple example of routing with Vue 2.0 without using vue-router. This branch uses the raw HTML5 History API. For an example integrating a 3rd-party routing solution, see the pagejs branch.

Build Setup

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build

For a detailed explanation of the build process, read the docs for vue-loader.