zoukankan      html  css  js  c++  java
  • vue项目build后,服务器中运行程序成功,但是刷新页面以后就挂了

    方法一:

    将 mode: 'history' 中的history 替换为 'hash'

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

    方法二:

    了解    HTML5 History 模式 :https://router.vuejs.org/zh/guide/essentials/history-mode.html

    如果不想要很丑的 hash,就要用路由的 history 模式,通过修改 history后端配置 来解决问题

    后端配置例子

    #Apache

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index.html$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.html [L]
    </IfModule>

    除了 mod_rewrite,你也可以使用 FallbackResource

    #nginx

    location / {
      try_files $uri $uri/ /index.html;
    }

    #原生 Node.js

    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)
    })
  • 相关阅读:
    C++---使用类
    C++---函数
    C++---指针和引用
    C++---面向对象
    C++---数组
    C++---条件结构和循环结构
    C++---变量、数据类型和运算符
    C++---初识C++
    MySQL---什么是事务
    MySQL---char和varchar的区别
  • 原文地址:https://www.cnblogs.com/miny-simp/p/9100851.html
Copyright © 2011-2022 走看看