02.【手写vue-router】提取路由信息

2020-04-26  本文已影响0人  章音十
class myRouter {
  constructor(options){
    this.mode = options.mode || 'hash';
    this.routes = options.routes || [];
    // 提取路由信息
    this.routesMap = this.createRoutesMap();
    console.log(this.routesMap);
 }
  createRoutesMap(){
    return  this.routes.reduce((map, route)=>{
        map[route.path] = route.component;
        return map;
      }, {})
   }
}
myRouter.install = (Vue, options)=>{

}
export default myRouter;
上一篇 下一篇

猜你喜欢

热点阅读