admin管理员组文章数量:1332329
I am deploying a React project using Vite to GitHub Pages. My GitHub Pages URL is: /
I have a project called cv_wizardy, so the project should be accessible at: /
However, when I deploy and upload the project files, the root JavaScript only renders when the path is set to the absolute path /
. It does not work correctly when accessed via the relative path /.
Setup:
I'm using Vite with React.
The issue occurs with the JavaScript files that seem to be looking for the root directory (/
) instead of the /cv_wizardy/
subpath.
I've also checked that the repository is correctly configured to use GitHub Pages. What am I missing or doing wrong here? How can I make the project work with the correct relative paths?
I've ensured the base property in vite.config.ts
is set to /cv_wizardy/
:
export default defineConfig(({ mode }) => ({
base: '/cv_wizardy/',
plugins: [
react(),
mode === "development" && componentTagger(),
].filter(Boolean),
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
}));
I am deploying a React project using Vite to GitHub Pages. My GitHub Pages URL is: https://adelelawady.github.io/
I have a project called cv_wizardy, so the project should be accessible at: https://adelelawady.github.io/cv_wizardy/
However, when I deploy and upload the project files, the root JavaScript only renders when the path is set to the absolute path /
. It does not work correctly when accessed via the relative path https://adelelawady.github.io/cv_wizardy/.
Setup:
I'm using Vite with React.
The issue occurs with the JavaScript files that seem to be looking for the root directory (/
) instead of the /cv_wizardy/
subpath.
I've also checked that the repository is correctly configured to use GitHub Pages. What am I missing or doing wrong here? How can I make the project work with the correct relative paths?
I've ensured the base property in vite.config.ts
is set to /cv_wizardy/
:
export default defineConfig(({ mode }) => ({
base: '/cv_wizardy/',
plugins: [
react(),
mode === "development" && componentTagger(),
].filter(Boolean),
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
}));
Share
Improve this question
edited Feb 3 at 16:43
rozsazoltan
9,8256 gold badges19 silver badges45 bronze badges
asked Nov 20, 2024 at 18:37
Adel Ali MohamedAdel Ali Mohamed
13 bronze badges
1 Answer
Reset to default 0you can try to use relative path, vite build
use absolute path by default, but Github Page can't solve absolute path now.
- <link rel="stylesheet" crossorigin href="/cv_wizardy/assets/index-DSvXlYyr.css">
+ <link rel="stylesheet" crossorigin href="assets/index-DSvXlYyr.css">
ref: GitHub pages and absolute paths
本文标签: GitHub Pages with Vite and React Absolute Path Issue for JavaScript RenderingStack Overflow
版权声明:本文标题:GitHub Pages with Vite and React: Absolute Path Issue for JavaScript Rendering - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742337138a2455851.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论