Namkaz Subs
Namkaz Subs

Reputation: 13

Can i use a laravel router and a react router together?

Example ....

i Have route React



function App() {
  return (
      <React.Fragment>

        <Router>

          <Switch>
            <Route exact path="/" component={list} />
            <Route exact path="/p/:id" component={Post} />
          </Switch>

        </Router>

      </React.Fragment>
  )
}



export default App;

And I Have Route in Laravel

Screenshot : http://prntscr.com/ov80dm

but when i am try .. i get blank page ... anyone know the solution ?

Upvotes: 0

Views: 60

Answers (1)

ankith vishwakarma
ankith vishwakarma

Reputation: 104

No, you can't but you can write a wildcard any route in web.php, so that every route get redirected to a single view where the js is imported. Then let the react router work accordingly.

Route::get('/{any}', function () { return view('base.blade') })->where('any', '.*');

Upvotes: 1

Related Questions