react-laravel icon indicating copy to clipboard operation
react-laravel copied to clipboard

Best way to connect laravel routes and react-router?

Open brenelz opened this issue 9 years ago • 11 comments

Loving this package... got this all working in an app.

One question I have is how would you hook up the routing. I see 2 options.

  1. Keep client-side routing on the client - and only use Laravel for api stuff or full page reloads
  2. Pass Laravel routes to the react-router if they don't exist (404)

Thoughts?

brenelz avatar Apr 15 '15 13:04 brenelz

Huum, for now I would use the first option, the second seems wrong.

But, as I said, it's for now, I'm planning to create a @react_router directive soon !

talyssonoc avatar Apr 16 '15 17:04 talyssonoc

That sounds pretty cool... why would you write your react routes in blade though?

brenelz avatar Apr 16 '15 20:04 brenelz

Actually I wouldn't, the directive would mount and run the router, as the @react_component do for components, I'm still thinking about it, suggestions are welcome.

talyssonoc avatar Apr 16 '15 20:04 talyssonoc

I do think connecting the routing somehow would be pretty awesome. Just thinking myself how I would like that to work.

brenelz avatar Apr 16 '15 21:04 brenelz

Hey, @brenelz, sorry by the delay, I've been busy ! I'm thinking about building something using laroute, what do you think ?

talyssonoc avatar Jun 17 '15 11:06 talyssonoc

@brenelz good direction we need something like isomorphic app .

send to client all route needed for the page if javascript fallback or client going to other page route it from the server.

a-moses avatar Jun 20 '15 10:06 a-moses

@talyssonoc I like the laroute idea. For me, the real appeal of a client-side app is the quick response of the UI, as the app only gets page specific (often Json) data from the server, following navigation. Would this allow us to access important Laravel features like route specific middleware, and route bindings?

karlonauger avatar Jul 10 '15 08:07 karlonauger

Hi, @karlonauger, as it would just generate the URL for the route I would say yes, it would allow access to middlewares and so on. I think it would let React just make ajax requests to the given URL and, there, you can say what will be sent to the client (something like this pjax example: https://github.com/defunkt/jquery-pjax#server-side), what do you think ?

talyssonoc avatar Jul 10 '15 12:07 talyssonoc

That sounds great! It would save me a ton of time trying to re-design, and duplicate client-side authentication.

karlonauger avatar Jul 10 '15 18:07 karlonauger

Hey there, any update on this ? Cheers ;)

yukulelix avatar Apr 06 '16 10:04 yukulelix

Do you know how to access direct a permanent link create by react creating the route in laravel?

henfreire avatar Jul 23 '18 21:07 henfreire