Fix image paths: Change from /react/templateassets/ to /react/assets/
- Update package.json homepage from /react/template/ to /react/ - Update environment.jsx base_path to /react/ with proper fallback - Enhance ImageWithBasePath component to handle path concatenation correctly - Ensure proper slash handling between base_path and image src paths
This commit is contained in:
parent
3d34f67c3f
commit
f851ff0fa5
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "my-app",
|
"name": "my-app",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"homepage": "/react/template/",
|
"homepage": "/react/",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ckeditor/ckeditor5-build-classic": "^41.2.0",
|
"@ckeditor/ckeditor5-build-classic": "^41.2.0",
|
||||||
|
|||||||
@ -1,9 +1,23 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import PropTypes from "prop-types"; // Import PropTypes
|
import PropTypes from "prop-types"; // Import PropTypes
|
||||||
import { base_path } from "../../environment";
|
import { base_path } from "../../environment";
|
||||||
|
|
||||||
const ImageWithBasePath = (props) => {
|
const ImageWithBasePath = (props) => {
|
||||||
// Combine the base path and the provided src to create the full image source URL
|
// Combine the base path and the provided src to create the full image source URL
|
||||||
const fullSrc = `${base_path}${props.src}`;
|
// Handle both relative and absolute paths
|
||||||
|
let fullSrc;
|
||||||
|
if (props.src.startsWith('http')) {
|
||||||
|
fullSrc = props.src;
|
||||||
|
} else {
|
||||||
|
// Ensure there's always a slash between base_path and src
|
||||||
|
const cleanBasePath = base_path.endsWith('/') ? base_path : base_path + '/';
|
||||||
|
const cleanSrc = props.src.startsWith('/') ? props.src.substring(1) : props.src;
|
||||||
|
fullSrc = `${cleanBasePath}${cleanSrc}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For debugging - remove in production
|
||||||
|
// console.log('Image path:', fullSrc);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<img
|
<img
|
||||||
className={props.className}
|
className={props.className}
|
||||||
@ -12,6 +26,11 @@ const ImageWithBasePath = (props) => {
|
|||||||
alt={props.alt}
|
alt={props.alt}
|
||||||
width={props.width}
|
width={props.width}
|
||||||
id={props.id}
|
id={props.id}
|
||||||
|
onError={() => {
|
||||||
|
console.error(`Failed to load image: ${fullSrc}`);
|
||||||
|
// Optionally set a fallback image
|
||||||
|
// e.target.src = `${base_path}assets/img/placeholder.png`;
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,2 +1,5 @@
|
|||||||
// export const base_path = "/react/template/";
|
// For development environment
|
||||||
export const base_path = "/";
|
export const base_path = process.env.PUBLIC_URL || "/react/";
|
||||||
|
|
||||||
|
// For production with a subdirectory (uncomment and modify as needed)
|
||||||
|
// export const base_path = "/react/";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user