基于 Vue 为非单页应用设计的前端 Router

2,978 阅读1分钟

In fact, it's not simple at all, it's just made for Non-Single-Page applications.

Installation

npm install vue-simple-router --save-dev

Example

import router from 'vue-simple-router';

// define a view for homepage:
// first define a footer element:
const footer = {
  el: '#footer',
  data () {
    return { year: 2015 };
  }
};
const home = {
  data () {
    return { siteName: 'Home' };
  },
  kids: [footer]
};

// map routes, support /user/* style minimatch
router.map({
  '/': {
    view: home
  }
});

// initial router and bind it to body
router.init();
// or bind to anywhere
router.init('#app');

// alias routes
router.alias('/u/sox', '/user/egoist');
// support minimatch too
router.alias('/u/*', '/user/egoist');

License

MIT © EGOIST.