npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-component-router

v0.1.17

Published

Component-based routing for vue. Inspired by react router 4

Downloads

133

Readme

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.