路由器的两种工作模式+项目上线的基本流程
hash模式
前面案例的地址栏目有#号实际上
![](https://img-blog.csdnimg.cn/img_convert/05d2f881619f7eeee37f69eb693c0167.png)
路径开始#开始到末尾都是路径里面的hash值,特点:不会随http请求发给服务器
启动服务器http://localhost:5000/students
node .\server1.js
![](https://img-blog.csdnimg.cn/img_convert/a2cab9e9ad599f28efabe2ffb6a192d5.png)
启动hash模式不会影响访问路径
![](https://img-blog.csdnimg.cn/img_convert/79a6946947a7f91943642dc1399c7831.png)
不是hash模式会影响
![](https://img-blog.csdnimg.cn/img_convert/7957e9d32eca56abe28f98b81de478fe.png)
_history模式
在路由配置规则里面改 配置项mode 默认的是hash 改成history
mode:'history'
![](https://img-blog.csdnimg.cn/img_convert/e8ddb334cb2713fcdc1c723101caefe7.png)
没有了#号了
![](https://img-blog.csdnimg.cn/img_convert/dd5c84c614c9029b4cabd91c11371757.png)
#兼容性好 /美观
项目上线流程
将所有写的东西打包--vue变成 .html .js .css
我们目前使用的都是npm run serve
![](https://img-blog.csdnimg.cn/img_convert/75f5c6ddad57a45171a9625fd16b895e.png)
现在要换成build ==》npm run bulid
npm run build
![](https://img-blog.csdnimg.cn/img_convert/48462c66e6acddc576db3cd795610919.png)
生成了新的文件
![](https://img-blog.csdnimg.cn/img_convert/f837298d95a77504a114acd019145fef.png)
map是webpack的映射文件
![](https://img-blog.csdnimg.cn/img_convert/7f11bdedcc5e7c5f3b38aea1c687bef1.png)
双击不能代开,打包的文件需要放在服务器上,进行一个部署才能运行
创建简单服务器
新建文件夹
npm init -y
创建服务器
//导入express
const express=require('express')
//创建web服务器
const app=express()
//监听客户端的GET请求和POST请求,并向客户端响应具体内容
app.get('/person',function(req,res){
res.send(
{"name":"zj","age":66,"gender":"男"}
)
})
//启动服务器.lisen(端口号,(启动成功职之后的回调函数)) 端口号是80可以省略
app.listen(5007,()=>{
console.log('如果启动成功,则客户端为http://127.0.0.1:5007 ,打印这一行输出')
})
创建静态资源目录,使用express插入静态资源
![](https://img-blog.csdnimg.cn/img_convert/19b45e0cef65659782fe34eabca7db76.png)
![](https://img-blog.csdnimg.cn/img_convert/489b08af649c704f5c0cc1e453489428.png)
可以进行访问
![](https://img-blog.csdnimg.cn/img_convert/ba756e7c9d98a3b78f4ca5fdab059900.png)
将前面的dist文件的内容全部放入静态资源的文件,如果是index.html可以省略
![](https://img-blog.csdnimg.cn/img_convert/643e5b2709cf9cee2e50d15431a6e026.png)
点击可以--不发送网络请求,影响的history模式
![](https://img-blog.csdnimg.cn/img_convert/8f66365b0360f8506ed7ff97e977135c.png)
刷新了history就变成资源请求了,但是hash就没影响了
![](https://img-blog.csdnimg.cn/img_convert/c5c302c349157a2369fa4651a9485b79.png)
解决办法:后端配合--使用正则匹配 或者使用中间件npm i connect-history-api-fallback 解决history404
npm i connect-history-api-fallback
![](https://img-blog.csdnimg.cn/img_convert/03f83149a0f5096a36ab3b3e5f42da3b.png)
![](https://img-blog.csdnimg.cn/img_convert/3b2bf0c188a9d7ff6d8040936b1592fe.png)