历史
当前端和后端没有分开时,路由由服务器控制。正面/访问者 - > http请求 - >服务器 - >根据不同的URL路径,返回不同的html/data
这种pa的缺点和优势通常很明显
优点:SEO效果很好,直接返回HTML,屏幕的时间消耗(浏览器地址输入UR到任何元素显示页面上的emply->)
缺点:按下服务器,并将HTML进程放在服务器上。
单页应用程序
当前端和后端没有分开时,路由由服务器控制。正面/访问者 - > http请求 - >服务器 - >根据不同的URL路径,返回不同的html/data
这种pa的缺点和优势通常很明显
优点:SEO效果很好,直接返回HTML,屏幕的时间消耗(浏览器地址输入UR到任何元素显示页面上的emply->)
缺点:按下服务器,并将HTML进程放在服务器上。
vue->有,hestory反应 - >哈希,历史记录
要求:页面上的交互不会刷新页面;不同的URL将呈现不同的内容
哈希和历史有什么区别
功能www.baidu.com/#/user-> http-> www.baidu.com/ www.baidu.com/#/list/list/lide/1-> http-> www.baidu.com/
location.hash ='#aaa';locally.hash ='#bbb';从#AAA到#BBB,页面不会刷新
①。位置
②。如何标记HTML标签
哈希有一个#符号,不漂亮,服务器无法接收哈希路径和参数,历史记录没有
HTML5历史API
PUSHSTATE/替代的PUSHSTATE,在页面的浏览记录中添加历史记录替代记录,替换当前的历史记录
相关问题:PushState时它会触发Popstate吗?
答:PushState/替换不会触发PopState事件。目前,我们需要手动触发页面的重新填充。
问:何时会触发popstate。
答案:单击“浏览器”返回按钮;单击“浏览器前向”按钮;JS调用背面方法;JS调用方法;JS呼叫Go方法
NGINX配置1.索引。HTML在服务器本地存在(NGINX部署不在A服务器中,索引文件也位于A服务器中)))))
2. index.html存在远程服务器,OSS/CDN
//历史路由
班级baseRouter {
constructor(){
this.routes = {};
// location.hash;哈希方法
this.init(本地(本地);
this._bindpopstate();
}
init(路径){
window.history.replacestate({{{{
小路
},null,路径);
const cb = this.routes [path];
// cb && cb();
if(cb){{{
CB();
}
}
路线(路径,回调){
this.routes [path] =回调||功能 () {};
}
去(路径){
//跳转并执行相应的回调
window.history.pushstate({
小路
},null,路径);
const cb = this.routes [path];
// cb && cb();
if(cb){{{
CB();
}
}
_bindpopstate(){
//说明触发流行事件后会发生什么
window.addeventlistener('popstate',(e)=> {
const路径= e.state && e.state.path;
console.log(`在popstate侦听器路径中= $ {path}`);
this.routes [path] && this.routes [path]();
})
}
}
const Router = new Baseer();
const body = document.queryselector('hody');
函数changebgcolor(color){
Body.Style.BackgroundColor =颜色;
}
router.route('/',function(){
changebgcolor('White');
});
router.route('/gray',function(){
changebgcolor('灰色');
});
router.route('/green',function(){
changebgcolor('green');
});