当前位置:网站首页>When the vite multi-page application refreshes the page, it will not be in the current route and will return to the root route
When the vite multi-page application refreshes the page, it will not be in the current route and will return to the root route
2022-07-30 15:43:00 【Zheng One Dream】
When we use vite to develop multi-page applications
If there is a route in another page, then we will have a problem refreshing the page
vite does not have a serverFallback method similar to webpack
For example:
When we visit /nested/ it's right, it goes to the /nested item
When we visit /nested/getInfo/xx and other routes, refresh the page and find that the page will go back to the root project instead of the current project
We did not send the configuration static path rollback, my current solution is:
plugins: [{name: "rewrite-middleware",configureServer(serve) {serve.middlewares.use((req, res, next) => {if (req.url.startsWith("/nested/")) {if (req.url.includes("src")) {req.url = req.url} else {req.url = "/nested/"}}next()})},}]Add a plugin to force the path to the /nested/ project
But the problem is, he has static resources, such as the includes('src') I wrote, what if he has multiple static resources?
I can't judge whether it is a route or a static resource. I have written an issue and will continue to follow up to solve this problem and find the best solution
The above is my personal solution
==========================================
The official staff gave me some suggestions, the best solution now is to encapsulate it into a function (the best way I can think of)
I encapsulated my plugin into a function that can receive parameters, so at least it feels pretty good to use
const rewritePlugin = (path, excludes) => ({name: "rewrite-middleware",configureServer(serve) {serve.middlewares.use((req, res, next) => {if (req.url.startsWith(path)) {const isRaw = excludes.some((dir) => req.url.includes(dir))if (!isRaw) req.url = path}next()})},})// The second parameter, see which folders are in your project, just write them allplugins: [rewritePlugin('/nested/', ['/nested/src', '/nested/static'])]边栏推荐
猜你喜欢

瑞吉外卖项目实战Day02

(Crypto必备干货)详细分析目前NFT的几大交易市场

解析字符串拼接的两种情况
4 senior experts share the insider architecture design and implementation principles of Flink technology with years of experience in large factories

GUCCI、LV等奢侈品巨头如何布局元宇宙的,其他品牌应该跟上吗?

数据库-SQL

Example of video switching playback (video switching example) code

Distributed pre-course: MySQL implements distributed locks

Huawei issues another summoning order for "Genius Boys"!He, who had given up an annual salary of 3.6 million, also made his debut

Flask introductory learning tutorial
随机推荐
[Cloud native] Grayscale release, blue-green release, rolling release, grayscale release explanation
工具| execsnoop 短时进程追踪工具
Local Transactions vs Distributed Transactions
Alluxio for Presto fu can across the cloud self-service ability
ECCV2022 | FPN错位对齐,实现高效半监督目标检测 (PseCo)
4 senior experts share the insider architecture design and implementation principles of Flink technology with years of experience in large factories
vite 多页面应用刷新页面时,不会在当前路由中,会返回到根路由
Placement Rules 使用文档
L2-007 家庭房产(vector、set、map的使用)
组态 - 笔记
【云原生】服务行业案例-不可预测的并发场景解决方案
嵌入式开发:嵌入式基础知识——正确启动固件项目的 10 条建议
Nature Microbiology综述:聚焦藻际--浮游植物和细菌互作的生态界面
CS内网横向移动 模拟渗透实操 超详细
Classes and Objects (Part 2)
TensorFlow自定义训练函数
TensorFlow custom training function
2022最新 | 室外单目深度估计研究综述
[In-depth study of 4G/5G/6G topic-46]: 5G Link Adaption Link Adaption-2-Common Abbreviations
数据库-SQL