• 前端路由-JS实现


    /*
    *	路由源于服务器端的概念
    *	路由在服务端是URL到控制器(处理函数的映射)
    *	路由在前端是URL到UI的映射
    */ 
    
    ;(function () {
    
    	function Router(){
    		this.historyStack = []; // 记录跳转历史
    		this.registerRouter = []; // 记录已注册的路由
    		this.defalutRouter = {
    			path: '/',
    			content: 'default page!'
    		}; // 路由匹配失败时的跳转地址
    	}
    
    	// 路由启用
    	Router.prototype.init = function() {
    		
    	};
    
    	// 绑定 hashchange 事件的回调函数
    	Router.prototype._bindEvents = function(){
    
    	}
    
    	// 路由注册方法
    	Router.prototype.add = function(path, content){
    
    	}
    
    	// 判断新增路由是否存在
    	Router.prototype.isHasRouter = function(path){
    
    	}
    
    	// 路由不存在时的默认路由
    	Router.prototype.default = function(path, content){
    
    	}
    
    	// 路由跳转方法
    	Router.prototype.go = function(path){
    
    	}
    
    	// 渲染对应路由信息到页面
    	Router.prototype.render = function(content){
    
    	}
    
    	var router = new Router()
    	window.$router = router; // 将接口暴露到全局
    
    })()
    

      

  • 相关阅读:
    【转】html的meta总结
    style.left 与offsetLeft之间的区别
    VM886
    js 获取数据类型
    JS序列化URL方法
    userData 本地存储
    第一章 1.6 HTML5 的新功能(二)
    第一章 1.6 HTML5 的新功能(一)
    第一章 1.5 无插件范式
    第一章 1.4 新的认识
  • 原文地址:https://www.cnblogs.com/winyh/p/15084398.html
Copyright © 2020-2023  润新知