zoukankan      html  css  js  c++  java
  • vue-router-9-HTML5 History 模式

    vue-router 默认 hash 模式,页面不会重新加载

    用路由的 history 模式,利用 history.pushState API 来完成 URL 跳转而无须重新加载页面。

    const router = new VueRouter({
      mode: 'history',
      routes: [...]
    })

    需要服务端支持,服务端增加一个覆盖所有情况的候选资源:如果 URL 匹配不到任何静态资源,则应该返回同一个 index.html 页面,这个页面就是你 app 依赖的页面。

    //例,基于node的配置
    const http = require('http')
    const fs = require('fs')
    const httpPort = 80
    
    http.createServer((req, res) => {
      fs.readFile('index.htm', 'utf-8', (err, content) => {
        if (err) {
          console.log('We cannot open 'index.htm' file.')
        }
    
        res.writeHead(200, {
          'Content-Type': 'text/html; charset=utf-8'
        })
    
        res.end(content)
      })
    }).listen(httpPort, () => {
      console.log('Server listening on: http://localhost:%s', httpPort)
    })
  • 相关阅读:
    Springmvc数据验证
    Springmvc文件上传
    BaseController
    说说NSProxy
    Objective-C的动态设计
    UITableView卡片式分组
    RunLoop应用之性能优化
    OC与JS交互之JavaScriptCore
    Core Data 迁移
    一个广告轮播视图的实现
  • 原文地址:https://www.cnblogs.com/avidya/p/7649170.html
Copyright © 2011-2022 走看看