How to deploy a React App on Apache web server

后端 未结 8 2159
谎友^
谎友^ 2020-11-29 18:11

I have created a basic React App from https://www.tutorialspoint.com/reactjs/reactjs_jsx.htm here , I want to run this test code on Apache based server, I know that I need t

8条回答
  •  醉酒成梦
    2020-11-29 18:52

    As well described in React's official docs, If you use routers that use the HTML5 pushState history API under the hood, you just need to below content to .htaccess file in public directory of your react-app.

    Options -MultiViews
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.html [QSA,L]
    

    And if using relative path update the package.json like this:

    "homepage": ".",
    

    Note: If you are using react-router@^4, you can root using the basename prop on any .

    import React from 'react';
    import BrowserRouter as Router from 'react-router-dom';
    ...
    
    
    

提交回复
热议问题