React + React Router + Laravel => error while performing refresh or insert url manually in browser

Asked

Viewed 118 times

1

I’m using React for the front of an application in Windows. In React, through the React-router I am accessing components dynamically through the parameters passed via url by the router link. If you leave the default settings for the Laravel,

 Route::get('/', function () {
   return view('main');
 });

if you refresh the page or manually insert the url in the browser drops to page 404. I found this way to avoid this:

Route::any('{all}', function () {
return view('main');
})
->where(['all' => '.*']);

However this only works for the first bar after the server address. ex:

works:

http:127.0.0.1:8000/rota1

but it doesn’t work:

http:127.0.0.1:8000/rota1/subrota

In this case, when updating the page or entering a url manually, instead of falling into 404 the page is empty.

How I’m using the dynamic routes:

<Route exact path="/party/:action" component={OperationParty}/>          
<Route exact path="/party/:action/:id" render={(props) => 
       <OperationParty {...props} toogleLoading={this.setLoading} />}/>
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.