Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different behaviour using optional param with engine #275

Closed
nickcotton opened this issue May 27, 2021 · 4 comments
Closed

Different behaviour using optional param with engine #275

nickcotton opened this issue May 27, 2021 · 4 comments

Comments

@nickcotton
Copy link

Hi, noticing a very slight difference in behaviour when upgrading to v2. Have done my best to explain below with a short comparison. For some reason in v2 I'm getting an extra / on some paths when I wasn't under the previous version. Entirely possible this is down to user error but thought I would raise anyway.

routes.rb

Rails.application.routes.draw do
  constraints(MainDomainPatterns) do
    scope "(:store)", store: /au|gb|us/ do
      mount Planner::Engine, at: "/", as: :planner
    end
  end
end

Engine routes.rb

Planner::Engine.routes.draw do
  constraints(MainDomainPatterns) do
    scope "manage" do
      namespace :api, defaults: { format: :json } do
        post 'events/slugs/suggestions'
	  end
    end
  end
end

routes.js - 1.4.9

// planner.api_events_slugs_suggestions => /(:store)/manage/api/events/slugs/suggestions(.:format)
  // function(options)
  planner_api_events_slugs_suggestions_path: Utils.route([["format",false]], {}, [2,[2,[2,[7,"/",false],[1,[3,"store",false],false]],[7,"/",false]],[2,[6,"manage",false],[2,[7,"/",false],[2,[6,"api",false],[2,[7,"/",false],[2,[6,"events",false],[2,[7,"/",false],[2,[6,"slugs",false],[2,[7,"/",false],[2,[6,"suggestions",false],[1,[2,[8,".",false],[3,"format",false]],false]]]]]]]]]]])
console.log(Routes.planner_api_events_slugs_suggestions_path())
// /manage/api/events/slugs/suggestions

routes.js - 2.0.2

/**
  * Generates rails route to
  * /(:store)/manage/api/events/slugs/suggestions(.:format)
  * @param {object | undefined} options
  * @returns {string} route path
  */
 export const plannerApiEventsSlugsSuggestionsPath = __jsr.r({"format":{"d":"json"}}, [2,[2,[2,[7,"/"],[1,[3,"store"]]],[7,"/"]],[2,[6,"manage"],[2,[7,"/"],[2,[6,"api"],[2,[7,"/"],[2,[6,"events"],[2,[7,"/"],[2,[6,"slugs"],[2,[7,"/"],[2,[6,"suggestions"],[1,[2,[8,"."],[3,"format"]]]]]]]]]]]]]);
console.log(plannerApiEventsSlugsSuggestionsPath())
// //manage/api/events/slugs/suggestions
@bogdan bogdan closed this as completed in 55511c7 May 28, 2021
@bogdan
Copy link
Collaborator

bogdan commented May 28, 2021

Version 2.0.3 👍

@nickcotton
Copy link
Author

@bogdan Thanks for looking at that so quickly. Most appreciated. Have noticed the routes where we have an engine mounted at "/" are now correct but not others which are mounted inside an optional scope.

i.e. the following routes config is now working correctly

Rails.application.routes.draw do
  constraints(WeddingDomainPatterns) do
    mount Planner::Engine, at: "/", as: :wedding
  end
end

but this section is still not and did not create any diff between v2.0.2 and v2.0.3 after running rake js:routes.

Rails.application.routes.draw do
  constraints(MainDomainPatterns) do
    scope "(:store)", store: /au|gb|us/ do
      mount Planner::Engine, at: "/", as: :planner
    end
  end
end

Could that be a separate issue? Happy to create a new issue and can provide additional information if you'd like.

@bogdan
Copy link
Collaborator

bogdan commented May 31, 2021

@nickcotton fixed it in 8486232. can you check if it works for you?

@nickcotton
Copy link
Author

@bogdan Yes, have just tested and seems to be working perfectly for all our use cases now. Thanks, this has been really helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants