(function(global) {
function Router(){
this.before = null; //切换前
this.after = null; // 切换后
this.routes=[];
this.redirectRoute="";
this.routeId="";
};
Router.prototype = {
//获取路由的路径和详细参数
getParamsUrl: function() {
var hashDeatail = location.hash.split("?"),
hashName = hashDeatail[0].split("#")[1],//路由地址
params = hashDeatail[1] ? hashDeatail[1].split("&") : [],//参数内容
query = {};
for(var i = 0;i<params.length ; i++){
var item = params[i].split("=");
query[item[0]] = item[1]
}
return {
path:hashName,
query:query
}
},
原生JS简单的实现单页面Hash路由
最新推荐文章于 2022-06-19 18:21:14 发布