I needing use React Router with a Laravel project.
But when I create router on the React Router and try access, Laravel<
How about using ?
E.g.
import React from 'react';
import {
HashRouter,
Route,
Link
}from 'react-router-dom';
import Profile from './Profile';
export default class App extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
Profile
);
}
}
In Laravel's router...
Route::get('/', function(){
return view('index'); //This view is supposed to have the react app above
});
With HashRouter, your client side routing is done with # (Fragment Identifier), which is not read by Laravel's routing (i.e. server side routing)
Upon arriving this page, the URL is /.
Clicking the link will make the URL /#/profile and the component will appear.
After that, if you refresh the page, you wont' see the Route not exist error. This is because, from Laravel's perspective, the URL is still /. (The component Profile still remains there.)
https://reacttraining.com/react-router/web/api/HashRouter
Hope my explanation is clear.