search

Home  >  Q&A  >  body text

php - React-Router's BrowserHistory, not accessible directly

There is a React project that uses BrowserHistory and is placed on the Apache server. The project homepage is localhost:8081/home.

After I enter the homepage, I can jump to other subpages (subroutes), such as: localhost:8081/product

But the browser cannot access localhost:8081/product directly because the Apache server will parse this path

I can only access localhost:8081/#/product.

Is there any way to access it directly?

大家讲道理大家讲道理2820 days ago815

reply all(1)I'll reply

  • 習慣沉默

    習慣沉默2017-06-05 11:09:46

    Forward all requests to index.html

    Configure .htaccess file:

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteRule ^index\.html$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.html [L]
     </IfModule>

    reply
    0
  • Cancelreply