项目作者: dongnaebi

项目描述 :
router for weex as you can use some feature of vue-router
高级语言: JavaScript
项目地址: git://github.com/dongnaebi/weex-vue-router.git
创建时间: 2017-02-20T14:31:02Z
项目社区:https://github.com/dongnaebi/weex-vue-router

开源协议:

下载


Demo

xiazhou-weex

Install

  1. $ npm install weex-vue-router

Usage

  1. <template>
  2. <div>
  3. <div @click="jump('/product/123')"><text>Jump</text></div>
  4. </div>
  5. </template>
  1. import weexVueRouter from 'weex-vue-router'
  2. import routes from './native-router'//web-router and native-router need to be defined separately。
  3. Vue.use(weexVueRouter,{routes,weex})
  4. export default {
  5. methods:{
  6. jump(url) {
  7. this.$router.push(url)
  8. },
  9. getParams(){
  10. return this.$route.params
  11. }
  12. }
  13. }

Construction options

  1. //native-router.js
  2. const domain='http://domain.com';
  3. const routes = [{
  4. path:'/product/:id';
  5. component:domain+'/dist/product/detail.js';//js bundle address,must end with '.js'
  6. name:'product';
  7. }];
  8. export default routes;

Component injections

$router

  • push() -only surport string featrue, like /path/:foo/:bar
  • back()

$route

  • path
  • params
  • query
  • hash
  • fullpath
  • matched
  • name

原理(求翻译)

需编译成两套,web端使用vue-router做SPA架构,单独编译出一个js(demo中的dist/app.js)。

native端则对应.vue文件编译成js bundle(demo中app/pages目录下的文件编译后分别对应dist中的js文件)。

在组件中写跳转$this.router.push('/path/1'),web端用vue-router跳转。

native端接收到/path/1,对应自己定义的routes匹配出js bundle地址,并使用navigator.push()方法跳转

TODO

  • 分模块&更严谨的逻辑
  • 加单测
  • meta和别名