diff --git a/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionExtensions.kt b/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionExtensions.kt index 116f10b85b..fa213bf212 100644 --- a/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionExtensions.kt +++ b/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionExtensions.kt @@ -60,7 +60,6 @@ fun RouterFunction<*>.route(request: ServerRequest, configure: Routes.() -> Unit class Routes { - val children = mutableListOf() val routes = mutableListOf>() infix fun RequestPredicate.and(other: RequestPredicate): RequestPredicate = this.and(other) @@ -69,8 +68,9 @@ class Routes { operator fun RequestPredicate.not(): RequestPredicate = this.negate() - fun RequestPredicate.route(routes: Routes.() -> Unit) = - RouterFunctions.nest(this, Routes().apply(routes).router()) + fun RequestPredicate.route(r: Routes.() -> Unit) { + routes += RouterFunctions.nest(this, Routes().apply(r).router()) + } operator fun RequestPredicate.invoke(f: (ServerRequest) -> Mono) { routes += RouterFunctions.route(this, HandlerFunction { f(it) }) @@ -145,20 +145,11 @@ class Routes { } fun router(): RouterFunction { - return routes().reduce(RouterFunction::and) + return routes.reduce(RouterFunction::and) } operator fun invoke(request: ServerRequest): Mono> { return router().route(request) } - private fun routes(): List> { - val allRoutes = mutableListOf>() - allRoutes += routes - for (child in children) { - allRoutes += child.routes() - } - return allRoutes - } - }