hash模式实现前端路由
来源:互联网 发布:锐捷mac怎么设置 编辑:程序博客网 时间:2024/03/28 17:46
function Router() { this.routes = {}; this.currentUrl = ''; } Router.prototype.route = function(path, callback) { this.routes[path] = callback || function(){}; }; Router.prototype.refresh = function() { this.currentUrl = location.hash.slice(1) || '/'; this.routes[this.currentUrl](); }; Router.prototype.init = function() { window.addEventListener('load', this.refresh.bind(this), false); window.addEventListener('hashchange', this.refresh.bind(this), false); } window.Router = new Router(); window.Router.init(); Router.route('/', function() { console.log('home'); }); Router.route('/about', function() { console.log('about'); }); Router.route('/about/test', function() { console.log('about_test'); });
阅读全文
0 0
- hash模式实现前端路由
- JS单页面应用实现前端路由(hash)
- 前端路由实现
- 前端路由相关实现
- history实现前端路由
- 前端路由实现原理
- Javascript实现前端简单路由
- 前端路由的实现原理
- Director JS 实现前端路由
- 前端路由之hash,以及iframe页面直接传参
- 用director.js实现的前端路由
- 前端路由的不同方法实现
- 前端路由的两种实现原理
- 前端路由的两种实现原理
- 利用history.pushState实现前端路由
- 前端路由
- 前端路由
- 【前端路由】
- JZOJ 1330. 迎接仪式
- Shell文件的排序、合并和分割
- leetcode611: Valid Triangle Number
- Servlet 工程 web.xml 中的 servlet 和 servlet-mapping 标签
- UE4制作一团逼真的火焰
- hash模式实现前端路由
- 2017,我的大学,我的退役赛
- JavaScript算法学习
- Java设计模式:八、外观模式
- unity 读取精灵图Sprite
- 001 Python安装与环境变量的配置
- 洛谷P2015 二叉苹果树
- Linux帮助说明
- MySQL创建外键约束的报错Error : Can't create table '#sql-534_185' (errno: 150)