DEV Community

Paulo Collares
Paulo Collares

Posted on • Originally published at paulocollares.com.br on

1 1

Como configurar o React Router no Apache2

Como configurar o React Router no Apache2

Como configurar o Apache2 para funcionar adequadamente com as rotas do React Router. Com essas configurações será possível recarregar a pagina ou acessar uma rota diretamente pela URL no navegador.

  1. Adicione a linha ‘homepage’ no package.json:
"homepage": "/meu-site",
  1. Adicione o atributo ‘basename’ na tag BrowserRouter:
<BrowserRouter basename="/meu-site">
  1. Habilite o modulo ‘rewrite’ no apache:
sudo a2enmod rewrite
  1. Edite o arquivo ‘/etc/apache2/sites-available/000-default.conf’ e adicione a regra de reescrita dentro da tag VirtualHost:
<Directory "/var/www/html/meu-site">
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^ index.html [L]
</Directory>
  1. Reinicie o serviço do Apache:
sudo service apache2 restart
  1. Crie um diretório com o nome ‘meu-site’ em ‘/var/www/html’ e copie o código compilado para ele.

[]’s

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs