I have built a react app and I want to add it to my existing wordpress website. So basically when you visit mydomain/reactapp you should see the app. But for now I am getting a white page and in my console there is: 05123b.css 404 (Not Found)
Do i have to change something in my htaccess? Thanks
I have built a react app and I want to add it to my existing wordpress website. So basically when you visit mydomain/reactapp you should see the app. But for now I am getting a white page and in my console there is: https://www.mydomain.co.uk/static/css/main05123b.css 404 (Not Found)
Do i have to change something in my htaccess? Thanks
Share Improve this question edited May 12, 2018 at 17:09 Nathan Johnson 6,5286 gold badges30 silver badges49 bronze badges asked May 12, 2018 at 17:06 Wushu06 Wushu06 12 Answers
Reset to default 0You need to include scripts and styles properly as it has been done here https://github/radekzz/wordpress-react-in-theme
add_action( 'wp_enqueue_scripts', 'enqueue_my_react_app' );
function enqueue_my_react_app(){
foreach( glob( get_template_directory(). '/myReactApp/build/static/js/*.js' ) as $file ) {
// $file contains the name and extension of the file
$filename = substr($file, strrpos($file, '/') + 1); wp_enqueue_script( $filename, get_template_directory_uri().'/myReactApp/build/static/js/'.$filename);
} foreach( glob( get_template_directory(). '/myReactApp/build/static/css/*.css' ) as $file ) {
// $file contains the name and extension of the file
$filename = substr($file, strrpos($file, '/') + 1); wp_enqueue_style( $filename, get_template_directory_uri().'/myReactApp/build/static/css/'.$filename);
}
}
I just needed to change the publicPath inside my webpack.