Skip to content

Empty routes  #321

Open
Open
@BonBonSlick

Description

@BonBonSlick

Symfony 4.0.8
All cache cleared.
Followed steps
https://symfony.com/doc/master/bundles/FOSJsRoutingBundle/index.html

I do not have routing.yaml in config/, it is replaced with routes.xml. It does not accept resource parameter for route. Ok. Created routing.yaml, only for this package with single entry point

fos_js_routing:
    resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"

registered bundle, added fos_js_routing.yaml in config/packages/ folder.

    FOS\JsRoutingBundle\FOSJsRoutingBundle::class => ['all' => true],
fos_js_routing:
#    router: my_router_service
    cache_control:
        # All are optional, defaults shown
        public: false   # can be true (public) or false (private)
        maxage: null    # integer value, e.g. 300
        smaxage: null   # integer value, e.g. 300
        expires: null   # anything that can be fed to "new \DateTime($expires)", e.g. "5 minutes"
        vary: []        # string or array, e.g. "Cookie" or [ Cookie, Accept ]

linked files

       <script src="{{ asset('bundles/fosjsrouting/js/router.min.js') }}"></script>
        <script src="{{ asset('js/fos_js_routes.js') }}"></script> // tried also this way
        <script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>

dumping php bin/console fos:js-routing:dump
or generatined with flex .json file are empty

routes.js
fos.Router.setData({"base_url":"","routes":[],"prefix":"","host":"custom.host.locc","scheme":"http"});
.json
{"base_url":"","routes":[],"prefix":"","host":"custom.host.locc","scheme":"http"}

parameters XML

        <parameter key="router.request_context.host">custom.host.locc</parameter>
        <parameter key="router.request_context.scheme">https</parameter>

Why so? What im doing wrong

Activity

Wimble84

Wimble84 commented on May 6, 2018

@Wimble84

Did you expose your routes ?

jhfyang

jhfyang commented on Jul 19, 2018

@jhfyang

I to have empty routres ! What do you mean expose ? I do not see anywhere in the documentation telling that you need to expose your routes

BonBonSlick

BonBonSlick commented on Jul 21, 2018

@BonBonSlick
Author

I do not remember, removed package and developed own -_ - Maybe will try someday again.

carlospauluk

carlospauluk commented on Aug 14, 2018

@carlospauluk

Same here. fos_js_routes.json just returns with

{"base_url":"","routes":[],"prefix":"","host":"localhost","scheme":"http"}

stof

stof commented on Aug 14, 2018

@stof
Member

I do not have routing.yaml in config/, it is replaced with routes.xml. It does not accept resource parameter for rout

XML also supports importing other resources: https://symfony.com/doc/current/routing/external_resources.html

carlospauluk

carlospauluk commented on Aug 14, 2018

@carlospauluk

Think I find the solution:

Ok, I think I found the problem. Here it is:

Checking how the FOSJsRoutingBundle works, I found the ExposedRoutesExtractor.php , that checks if "isRouteExposed" on "getRoutes()" method.

I found that I needed to expose my routes by setting the 'exposed' = true option on the @route, like this:

/**
*
* @Route("/bse/pessoa/findByNome/{str}", name="bse_pessoa_findByNome", methods={"GET"}, options = { "expose" = true })
*
*/
public function findByNome($str = null)
{
[...]

But, even after that, FOSJsRoutingBundle continues not showing anyone.

In this Issue FriendsOfSymfony/FOSRestBundle#718 they said that routes defined by annotations (FOSRest routes???) was not caught by this ExposedRoutesExtractor, only if they were exposed in yaml.

So I dit it. On config/routes/annotations.yaml I added:

controllers:
resource: ../../src/Controller/
type: annotation
options:
expose: true

Voila.

php bin/console fos:js-routing:debug now shows all my routes.

PythooonUser

PythooonUser commented on May 24, 2019

@PythooonUser

Thanks @carlospauluk for finding this!

I had the same issue. However, bin/console fos:js-routing:debug was showing me the annotation exposed route already, but calling Routing.generate() resulted in an error.

With that static config approach it works. Which is a bummer, because now all routes are exposed by default. But I can live with that :)

versedi

versedi commented on Nov 13, 2019

@versedi

Did you expose your routes ?

Is it possible to expose routes while using yaml for routing definitions?

expose key is unsupported in YamlFileLoader.

Wimble84

Wimble84 commented on Nov 13, 2019

@Wimble84

Did you expose your routes ?

Is it possible to expose routes while using yaml for routing definitions?

expose key is unsupported in YamlFileLoader.

Yes it is, like this :

your_route_name:
    path: /path/{argument}
    controller: App\Controller\YourController::yourAction
    options:
        expose: true
versedi

versedi commented on Nov 13, 2019

@versedi

Did you expose your routes ?

Is it possible to expose routes while using yaml for routing definitions?
expose key is unsupported in YamlFileLoader.

Yes it is, like this :

your_route_name:
    path: /path/{argument}
    controller: App\Controller\YourController::yourAction
    options:
        expose: true

Thank you, my Google-Fu failed on me and couldn't find a single thing in the docs :)

o-alquimista

o-alquimista commented on Jan 19, 2020

@o-alquimista

I'm successfully exposing specific routes through their annotation:

@Route("/example", name="example", options={"expose"=true})

Perhaps that means the issue @carlospauluk described is solved?

I think the documentation needs to put more emphasis on the need to expose the routes, and the many ways to do it, right before Generating URIs.

EliaCools

EliaCools commented on Sep 15, 2021

@EliaCools

Maybe you forgot to dump the newly exposed routes ? I overlooked this after exposing a route.
Symfony Flex
bin/console fos:js-routing:dump --format=json --target=public/js/fos_js_routes.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @stof@carlospauluk@Wimble84@versedi@BonBonSlick

        Issue actions

          Empty routes · Issue #321 · FriendsOfSymfony/FOSJsRoutingBundle