How to use React Router with Laravel?

0 votes

When I create router on the React Router and try access, Laravel accuse Route not exist error.

How to can I use React Router to manager Laravel project routes?

render((
    <Router history={browserHistory}>
        <Route path="/" component={App}/>
        <Route path="/profile" component={Profile}/> // this route I trying access
    </Router>
), document.getElementById('root'));
Apr 29 in Java-Script by kartik
• 11,890 points
99 views

1 answer to this question.

0 votes

Hii Kartik,

Create a route that maps everything to one controller, like so:

Route::get('/{path?}', [
    'uses' => 'ReactController@show',
    'as' => 'react',
    'where' => ['path' => '.*']
]);

Then in your controller, just show the HTML page that contains the react root document:

class ReactController extends Controller {
    public function show () {
        return view('react');
    }
}

Then do everything as normal with react router.

Hope this work fine!!

Thank You!!

answered Apr 29 by Niroj
• 23,950 points

Related Questions In Java-Script

0 votes
1 answer

How can I send a message to a particular client with socket.io?

Hii, You can try the code below: io.to(socket.id).emit("event", data); whenever ...READ MORE

answered Apr 27 in Java-Script by Niroj
• 23,950 points
73 views
0 votes
1 answer

How to set outerHTML with jQuery?

hello @kartik, This is innterHTML because it's inside ...READ MORE

answered Apr 27 in Java-Script by Niroj
• 23,950 points
31 views
0 votes
1 answer

How to call jQuery UI Dialog with ASP.NET button postback?

Hello @kartik, To solve the problem with ASP:Button ...READ MORE

answered Apr 28 in Java-Script by Niroj
• 23,950 points
57 views
0 votes
1 answer

How to do API call in react js?

Hello, Use fetch method inside componentDidMount to update state: componentDidMount(){ fetch('https://dey.me/api/') ...READ MORE

answered May 18 in Java-Script by Niroj
• 23,950 points
48 views
0 votes
1 answer

What is meant by passing the variable by value and reference in PHP?

Hello, When the variable is passed as value ...READ MORE

answered Mar 27 in PHP by Niroj
• 23,950 points
41 views
0 votes
1 answer

Connection with MySQL server using PHP. How can we do that?

Hey @kartik, You have to provide MySQL hostname, ...READ MORE

answered Mar 27 in PHP by Niroj
• 23,950 points
44 views
0 votes
1 answer

How to retrieve or obtain data from the MySQL database using PHP?

Hello kartik,  Actually there are many functions that  ...READ MORE

answered Mar 27 in PHP by Niroj
• 23,950 points
36 views
0 votes
1 answer

What are the differences between mysqli_connect and mysqli_pconnect?

Hello, mysqli_pconnect() function is used for making a persistence ...READ MORE

answered Mar 27 in PHP by Niroj
• 23,950 points
78 views
0 votes
1 answer

How to use Redirect in the new react-router-dom of Reactjs?

Hello, To navigate to another component you can ...READ MORE

answered May 18 in Java-Script by Niroj
• 23,950 points
31 views
0 votes
1 answer

How to get rid of underline for Link component of React Router?

Hello, If you are using styled-components, you could do ...READ MORE

answered May 18 in Java-Script by Niroj
• 23,950 points
40 views