FriendsOfSymfony / FOSJsRoutingBundle

A pretty nice way to expose your Symfony routing to client applications.
1.48k stars 261 forks source link

Routing isn't finding any routes #455

Closed jerrac closed 1 year ago

jerrac commented 1 year ago

This is my first time using FOSJsRoutingBundle, so I might have missed a step installing... But after double checking the docs a few times, I'm pretty sure I got it all set up correctly.

I have a Symfony 6.2 (php 8.1) app, running Webpack Encore. I know I have Encore setup correctly since my assets and stimulus controllers work. So I followed the installation steps for webpack.

At this point all my console.log will output is an empty Array. Both from the app.js call, and when my Stimulus controller method runs. It also will output a "route does not exist" error for any route I try to generate a url for. And I'm using routes listed in debug:router. I've tried routes with and without parameters.

Any insight on what I'm doing wrong would be appreciated.

Thanks in advance!

tobias-93 commented 1 year ago

Hi,

You need to add options: ['expose' => true] explicitly to all route definitions you want exposed on the JS side. Hope that helps.

jerrac commented 1 year ago

Awesome. That fixed it.

And now I see that setting in the docs...

Would it make sense to explicitly state that users need to apply that option? It's not something that was obvious to me, even though I went through that doc several times.