All Projects → blocka → Vue Component Router

blocka / Vue Component Router

Licence: mit
A component-based, declarative router for vue. Inspired by React Router 4

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Component Router

Urljects
Deprecated! (Django routing without urls.py files, inspired by Flask.)
Stars: ✭ 53 (-13.11%)
Mutual labels:  router
Dragon
⚡A powerful HTTP router and URL matcher for building Deno web servers.
Stars: ✭ 56 (-8.2%)
Mutual labels:  router
Livro Sem Apego
📚 Um site de doação de livros, sem fins lucrativos! o/
Stars: ✭ 58 (-4.92%)
Mutual labels:  vuejs2
Rainbow
An Express router middleware for RESTful API base on file path.
Stars: ✭ 53 (-13.11%)
Mutual labels:  router
Ska
Simple Karma Attack
Stars: ✭ 55 (-9.84%)
Mutual labels:  router
Zaneperfor
前端性能监控系统,消息队列,高可用,集群等相关架构
Stars: ✭ 1,085 (+1678.69%)
Mutual labels:  vuejs2
Tra Info
快速地查詢臺鐵時刻表,沒有廢話。
Stars: ✭ 53 (-13.11%)
Mutual labels:  vuejs2
Vue Flex
A reusable flexbox component using functional css and functional Vue components.
Stars: ✭ 61 (+0%)
Mutual labels:  vuejs2
Vue Vscode Snippets
These snippets were built to supercharge my workflow in the most seamless manner possible.
Stars: ✭ 1,083 (+1675.41%)
Mutual labels:  vuejs2
Kill Router
Ferramenta para quebrar senhas administrativas de roteadores Wireless, routers, switches e outras plataformas de gestão de serviços de rede autenticados.
Stars: ✭ 57 (-6.56%)
Mutual labels:  router
Svelte Store Router
Store-based router for Svelte
Stars: ✭ 54 (-11.48%)
Mutual labels:  router
Vuex Flash
VueJs Flash Message Component within Vuex
Stars: ✭ 54 (-11.48%)
Mutual labels:  vuejs2
Vuejs Aspnetcore Ssr
🆙 VueJS 2.5 Server Side Rendering on ASP.NET Core 2 and more
Stars: ✭ 57 (-6.56%)
Mutual labels:  vuejs2
Vuejs Carousel
Complete photo carousel build with VueJS and web standards in mind
Stars: ✭ 53 (-13.11%)
Mutual labels:  vuejs2
Vue Todo List
vue2.0+vuex+localStorage 待办事项
Stars: ✭ 61 (+0%)
Mutual labels:  vuejs2
Vue Social Sharing
A renderless Vue.js component for sharing links to social networks, compatible with SSR
Stars: ✭ 1,071 (+1655.74%)
Mutual labels:  vuejs2
Apprun
AppRun is a JavaScript library for developing high-performance and reliable web applications using the elm inspired architecture, events and components.
Stars: ✭ 1,087 (+1681.97%)
Mutual labels:  router
Vuejs By Sample
The goal of this project is to provide a set of step by step samples, covering core concepts of Vue.js
Stars: ✭ 61 (+0%)
Mutual labels:  vuejs2
Stf Vue Select
stf vue select - most flexible and customized select
Stars: ✭ 61 (+0%)
Mutual labels:  vuejs2
Linker
A light weight URI routing framework for Android.
Stars: ✭ 57 (-6.56%)
Mutual labels:  router

What is this?

This is a router based on components. It is a way of declaratively using routes, and has an api inspired by React Router 4.

Why? What's wrong with vue-router?

Nothing really. VueRouter is a fine project, which has tons of official support, and probably supports many more use-cases and edge cases than this. However, it does force you to define your entire route structure upfront. It also creates a slight disconnect between your routes and your UI, as if they were two separate things. Using components as a router feels very natural in a component based, declarative system, which Vue is.

This was also a good excuse to try out the new provide/inject feature of Vue 2.2+

Installation

npm install/yarn add vue-component-router

Basic Usage

<template>
<HistoryRouter>
    <div>
    <Route path="/contacts">
        <Contacts :contacts="contacts"></Contacts>
    </Route>
    <Route path="/contacts/:id">
        <Contact></Contact>
    </Route>
    </div>
</HistoryRouter>
</template>
<script>
import {HistoryRouter, Route, RouterLink} from 'vue-component-router';

export default {
   data () {
      return {
         contacts: ['Contact 1', 'Contact 2']
      };
   },
   components: {
      HistoryRouter,
      Route,
      Contacts: {
         props: ['contacts'],
         components: {RouterLink},
         template: `
           <ul>
                <li v-for="contact of contacts">
                   <RouterLink :to="`/contacts/${contact}`"></RouterLink>
                </li>
           </ul> `
      },
      Contact: {
         props: ['id'],
         template: `
         <div>{{id}}</div>
         `
      }
   }
}
</script>

Components

Router

Router acts as a provider to the various other components, or any other component which is decorated with withRouter, passing down the current location, and history object. It expects a location object, which has an API similar to window.location and a history object, with an API similar to window.history to be passed in as props.

HistoryRouter

A component which passes the browser's history and location (via the history module on npm) to Router. This is what you will want to use (in a browser).

Route

Take's two props, path and exact. Path takes an express style route (which is based on path-to-regexp), and if the browser's location matches that path, it will show the content. The content can either be a a component, or a scopedSlot. They will be passed the router parameters, the path that matched (useful for nesting routes), and the current url (useful for building nested links), either as props, or as parameters, respectively.

Passing in exact as true will make the route match exactly.

<Route path="something/:id">
   <template scope="{id, path, url}">
      {{id}} {{path}} {{url}}
   </template>
</Route>

RouterLink

Takes three props, to, activeClass (defaults to 'active') and tag (defaults to a). This will render a link tag which knows how to update the location, and will set an active class when the route matches the link. Passing in exact as true will only apply the active class if the route matches exactly.

MatchFirst

Expects a list of Routes as slots, and will render the first one that matches.

Redirect

Takes a prop to, and will cause the browser to redirect to that url

withRouter

A HOC which will inject the wrapped function and inject the router object, which contains the history and location objects

withHandleClick

A HOC that takes a component or tag, and returns a component that handles clicks similar to RouterLink. This enables using other components or tags as router links without <a> tags.

This function takes 3 parameters: tagOrComponent, to, and activeClass. They correspond to the props of RouterLink.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].