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

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

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

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay