diff --git a/src/think/Route.php b/src/think/Route.php index 6d26122f77..5ed3e5f54e 100644 --- a/src/think/Route.php +++ b/src/think/Route.php @@ -747,7 +747,7 @@ public function dispatch(Request $request, Closure | bool $withRoute = true) } $dispatch = $this->check($completeMatch); } else { - $dispatch = $this->autoUrl($this->config['default_route']) + $dispatch = $this->urlDispatch($this->config['default_route']) ->check($this->request, $this->path(), $completeMatch); } @@ -784,7 +784,7 @@ public function check(bool $completeMatch = false) } elseif ($this->config['url_route_must']) { throw new RouteNotFoundException(); } - return $this->autoUrl($this->config['default_route']) + return $this->urlDispatch($this->config['default_route']) ->check($this->request, $url, $completeMatch); } @@ -839,7 +839,7 @@ public function auto(string $rule = '[:module]/[:controller]/[:action]', $route * @param array $option 解析规则 * @return RuleItem */ - public function autoUrl(array $option = []): RuleItem + protected function urlDispatch(array $option = []): RuleItem { return $this->group->urlDispatch($option); } diff --git a/src/think/route/RuleGroup.php b/src/think/route/RuleGroup.php index 85c842526b..4016d14dbe 100644 --- a/src/think/route/RuleGroup.php +++ b/src/think/route/RuleGroup.php @@ -177,8 +177,10 @@ public function check(Request $request, string $url, bool $completeMatch = false } if ($this->urlDispatch) { - // 分组默认URL路由规则 - $result = $this->urlDispatch->check($request, $url, $completeMatch); + // 分组默认URL调度 + $result = $this->urlDispatch + ->option($this->getOption()) + ->check($request, $url, $completeMatch); } elseif ($miss = $this->getMissRule($method)) { // 未匹配所有路由的路由规则处理 $result = $miss->parseRule($request, '', $miss->getRoute(), $url, $miss->getOption()); @@ -363,7 +365,8 @@ protected function checkMergeRuleRegex(Request $request, array &$rules, string $ */ public function autoUrl(array $option = []) { - $this->urlDispatch($option); + $ruleItem = $this->urlDispatch($option); + $this->urlDispatch = $ruleItem; return $this; } @@ -386,16 +389,13 @@ public function urlDispatch(array $option = []): RuleItem $ruleItem = new UrlRuleItem($this->router, new RuleGroup($this->router), '_default_route_', $rule, $route); - $ruleItem = $ruleItem->default([ + return $ruleItem->default([ 'controller' => $this->config('default_controller'), 'action' => $this->config('default_action'), ])->pattern([ 'controller' => '[A-Za-z0-9\.\_]+', 'action' => '[A-Za-z0-9\_]+', - ])->option($this->getOption()); - - $this->urlDispatch = $ruleItem; - return $ruleItem; + ]); } /**