当前位置:网站首页>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'])]边栏推荐
猜你喜欢

Our company has used gateway services for 6 years, dynamic routing, authentication, current limiting, etc., a stable batch!

解析字符串拼接的两种情况
![[Cloud native] Alibaba Cloud ARMS business real-time monitoring](/img/e7/55f560196521d22f830b2caf110e34.png)
[Cloud native] Alibaba Cloud ARMS business real-time monitoring

timed task corn

Kubernetes应用管理深度剖析
![[Cloud Native] Service Industry Case - Solutions for Unpredictable Concurrency Scenarios](/img/c7/3faa29dc374e2e16e59ac9b8ebf249.png)
[Cloud Native] Service Industry Case - Solutions for Unpredictable Concurrency Scenarios

元宇宙的前景及四大赛道

Flask入门学习教程

Extremely Knowing v2 Analysis

About the data synchronization delay of MySQL master-slave replication
随机推荐
定时任务 corn
如何做好技术选型
nodejs环境变量设置
哨兵
GeoServer + openlayers
Changing SELECT...FROM to FROM...SELECT doesn't 'fix' SQL
被捧上天的Scrum敏捷管理为何不受大厂欢迎了?
How is the B+ tree index page size determined?
CMake库搜索函数居然不搜索LD_LIBRARY_PATH
tiup completion
MASM32v11编程调用Process32First失败: 程序发出命令,但命令长度不正确
TiDB tool download
Store Limit 使用文档
tiup help
数字量输入模块io
xxl-job源码解析(技术分享)
Applicable scenarios of TiDB tools
华为「天才少年」计划招募的博士们,迎来首秀!
Alluxio为Presto赋能跨云的自助服务能力
tiup clean