-1

I have built a react app and I want to add it to my existing wordpress website. So basically when you visit mydomain.com/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/main.cc05123b.css 404 (Not Found)

Do i have to change something in my htaccess? Thanks

0

You need to include scripts and styles properly as it has been done here https://github.com/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);   
}
 }
-2

I just needed to change the publicPath inside my webpack.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.