I have parent component that shows an image at a specified path (note: the image is already saved in my project). This path optionally can have additional parameters. If the
For example, The image is displayed (image) if the html path is:
www.mysite.com/myPath The component is displayed but image is broken (broken image) if the html path is:
www.mysite.com/myPath/someFilterForThisPage Router
// Libraries import React from 'react'; import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'; import { browserHistory } from 'react-router'; // Components import Home from './containers/Home'; import NotFound from './components/NotFound'; import MyComponent from './components/MyComponent'; // Redux import { Provider } from 'react-redux'; import {createStore} from 'redux'; import allReducers from './reducers'; const store = createStore( allReducers, window.devToolsExtension && window.devToolsExtension() ); // Routes const routes = ( <Router history={browserHistory}> <div> <Provider store={store}> <Switch> <Route path="/" exact component={Home} /> <Route path="/myPath/:filter?" component={MyComponent} /> <Route component={NotFound} /> </Switch> </Provider> </div> </Router> ); export default routes; I don't think the issue is with my router.js file since the component still shows when a filter is applied in the html path (the image is just broken,
), but I am providing it just in case I am misunderstanding something.
My Component:
// React import React from 'react'; class MyComponent extends React.Component { constructor(props) { super(props); } render() { <div> <img src={"img/x.png"} id="someId" alt=""/> // ISSUE // ... // some divs that show/don't based on the filter of the html path // ... </div> } } export default MyComponent; I have looked at and tried some of the following, but with little luck:
I think these are different because these are mainly issues related to being unable to display images at all. I am able to display the image, but only when the optional html parameter is not set.
Does anyone know why the image is showing, but only if there is no extra html parameter?
Many thanks.
imgfolder where that image is located, so this solution would mean stripping out every single image used throughout the project (which would be a significant number)