-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Labels
p3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Description
Description
Our website is made with VitePress and deployed on Cloudflare Pages. For redirects, we use Cloudflare's _redirects file, but this does only work on initial requests, not on secondary requests (due to single page) or during development.
To fix this, I imported the _redirects file:
import _redirects from "/_redirects?url&raw";
const redirects = _redirects
.split("\n")
.filter(String)
.map((item: string[]) => item.split(/\x20+/))
.filter(
(item: string) =>
item[0].indexOf(":") === -1 && item[0].indexOf("*") === -1,
);And then, inside the layout's enhanceApp function, I catch the redirects:
router.onAfterRouteChange = async (to: string) => {
// Static redirects
redirects.forEach((item: string[]) => {
if (
to === item[0] ||
to.startsWith(item[0] + "?") ||
to.startsWith(item[0] + "#")
) {
router.go(item[1]);
}
});
};This works fine, but I noticed that my IDE gave errors on the import line, caused by ?url&raw. I was not able to use ?raw directly, because of:
| throw new Error( |
Is there a reason why there isn't a declare module '*?url&raw' defined in Vite? Is a bug of Vite, or is my method badly wrong?
Suggested solution
Add:
declare module '*?url&raw' {
const src: string
export default src
}Alternative
No response
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Metadata
Metadata
Assignees
Labels
p3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)