最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Adding react app to an existing wordpress website

programmeradmin0浏览0评论

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 1
Add a comment  | 

2 Answers 2

Reset to default 0

You 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.

发布评论

评论列表(0)

  1. 暂无评论