How to use React Router with Laravel?

前端 未结 5 2005
温柔的废话
温柔的废话 2020-12-05 10:01

I needing use React Router with a Laravel project.

But when I create router on the React Router and try access, Laravel<

5条回答
  •  北海茫月
    2020-12-05 10:28

    Based on Jake Taylor answer (which is correct, by the way) : it has a little mistake, is missing a quotation mark after '/{path?}' , just the last one.

    Also, if you don't need to use a Controller and just redirect back to your view, you can use it like this:

    Route::get( '/{path?}', function(){
        return view( 'view' );
    } )->where('path', '.*');
    

    Note: Just make sure to add this Route at the end of all of your routes in the routes file ( web.php for Laravel 5.4 ), so every existing valid route you have may be catched before reaching this last one.

提交回复
热议问题