zoukankan      html  css  js  c++  java
  • spa 单页面解决浏览器back front 问题

    1.angular router

      reloadOnSearch:true(default) | false

        默认为true,当url的hash发生改变,页面新渲染,component会重新加载(初始化);

        false,当url的hash发生改变,页面不重新渲染,component不会重新加载(初始化);

    2.改变url的hash

      window.history.pushState({}, null, '?tab=home');改方法可以直接改变url的hash,并加入history;

    当前url为http://localhost:8888
    执行前:
    http://localhost:8888
    window.history.pushState({}, null, '?tab=home');
    执行后:
    http://localhost:8888?tab=home

         window.location.hash 取或者设置url的hash值,直接在url上面加入hash:

    当前url为http://localhost:8888
    执行前:http://localhost:8888
    window.location.hash = 'name=test';
    执行后:http:
    //localhost:8888?tab=home#name=test

         window.location.search 取或者url 通过pushState的值,方法类似window.history.pushState({}, null, '?tab=home');

     
  • 相关阅读:
    价值观
    周记 改
    周记
    C语言问卷调查
    icon踩坑记录
    console.log(a)和console.log(window.a)的区别?
    记录一次微信二次分享的优化过程
    在jQuery中使用自定义属性
    10个JS技巧
    日常工作总结 2019/10/10
  • 原文地址:https://www.cnblogs.com/rengised/p/6248525.html
Copyright © 2011-2022 走看看