【发布时间】:2023-03-08 19:44:02
【问题描述】:
我的路由文件中有一个奇怪的问题。 这是我需要了解的部分 这条路线不起作用
# V3
# V3 - Home Page
match '/:locale' => 'v3/home#index', :constraints => V3Constraint, :as => :home
# V3 - Search
match '(/:locale)/products/search' => 'v3/products#search', :constraints => V3Constraint
# V3 - Categories index
match '(/:locale)/categories/(:parent_category((/*path)/:category))/(:full)' => 'v3/products#index', :constraints => V3Constraint, :as => :category
# V3 - Prduct Page
match '/:locale/products/:product' => 'v3/products#show', :constraints => V3Constraint, :as => :product
match '(/:locale)/search_amazon' => 'v3/products#search_amazon', :constraints => V3Constraint
# EOF V3
但是这个工作
#V3 - Search
match '(/:locale)/products/search' => 'v3/products#search', :constraints => V3Constraint
# V3 - Categories index
match '(/:locale)/categories/(:parent_category((/*path)/:category))/(:full)' => 'v3/products#index', :constraints => V3Constraint, :as => :category
# V3 - Product Page
match '/:locale/products/:product' => 'v3/products#show', :constraints => V3Constraint, :as => :product
match '(/:locale)/search_amazon' => 'v3/products#search_amazon', :constraints => V3Constraint
# V3 - Home Page
match '/:locale' => 'v3/home#index', :constraints => V3Constraint, :as => :home
如果我使主页路由的优先级低于其他路由,则它可以工作,但如果它像其他路由一样位于顶部 这条路线: 匹配 '(/:locale)/search_amazon' => 'v3/products#search_amazon', :constraints => V3Constraint 将引导至主页。
谁能解释一下为什么会这样?
谢谢。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 routing routes rails-routing