J
J
Jedi2018-11-28 07:26:34
Laravel
Jedi, 2018-11-28 07:26:34

Why does React throw Not Found on page refresh?

Good morning!
Can you please tell me why this happens and how can I solve the problem?
I'm using React with Laravel, Apache throws an error.
Here is my code:
index.js:

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom'
import App from './components/App';

if (document.getElementById('example')) {
    ReactDOM.render(<BrowserRouter><App /></BrowserRouter>, document.getElementById('example'));
}

app.js:
import React, { Component } from 'react';
import { Switch, Route, Link } from 'react-router-dom';
import Tutorial from "./Tutorial";

const Sandwiches = () => <h2>Sandwiches</h2>;
const Tacos = () => <h2>Tacos</h2>;

class App extends Component {
    render() {
        return (
            <div>
                <ul>
                    <li><Link to='/sandwiches'>Sandwiches</Link></li>
                    <li><Link to='/tacos'>Tacos</Link></li>
                    <li><Link to='/tutorials'>Tutorials</Link></li>
                </ul>

                <Switch>
                    <Route exact path='/sandwiches' component={Sandwiches} />
                    <Route exact path='/tacos' component={Tacos} />
                    <Route exact path='/tutorials' component={Tutorial} />
                </Switch>
            </div>
        );
    }
}

export default App;

If you use routing from the starting point ( localhost:8080/), then everything works fine. And if I try to prescribe the following path, for example: localhost:8080/tacos, then here ...
5bfe18d69f657012479732.png
And when the page is updated, the same thing ...
Give me advice, please.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2018-11-28
@PHPjedi

Google "apache SPA configuration"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question