Skip to content

Commit 3f3d216

Browse files
committed
feat: improve spark routes output for View routes
1 parent c009117 commit 3f3d216

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎system/Router/DefinedRouteCollector.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public function collect(): Generator
5151
if (is_string($handler) || $handler instanceof Closure) {
5252

5353
if ($handler instanceof Closure) {
54-
$handler = '(Closure)';
54+
$view = $this->routeCollection->getRoutesOptions($route, $method)['view'] ?? false;
55+
56+
$handler = $view ? '(View) ' . $view : '(Closure)';
5557
}
5658

5759
$routeName = $this->routeCollection->getRoutesOptions($route)['as'] ?? $route;

‎system/Router/RouteCollection.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,10 @@ public function view(string $from, string $view, ?array $options = null): RouteC
11011101
->setData(['segments' => $data], 'raw')
11021102
->render($view, $options);
11031103

1104-
$this->create('get', $from, $to, $options);
1104+
$routeOptions = $options ?? [];
1105+
$routeOptions = array_merge($routeOptions, ['view' => $view]);
1106+
1107+
$this->create('get', $from, $to, $routeOptions);
11051108

11061109
return $this;
11071110
}

‎tests/system/Router/DefinedRouteCollectorTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function testCollect()
8282
'method' => 'get',
8383
'route' => 'about',
8484
'name' => 'about',
85-
'handler' => '(Closure)',
85+
'handler' => '(View) pages/about',
8686
],
8787
];
8888
$this->assertSame($expected, $definedRoutes);

0 commit comments

Comments
 (0)