From 9322e930c5efa42a05cb55e82250b7c891327f55 Mon Sep 17 00:00:00 2001 From: hhaensel Date: Wed, 27 Nov 2024 18:11:09 +0100 Subject: [PATCH] fix duplicate routes issue in Page() --- src/Pages.jl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Pages.jl b/src/Pages.jl index 4fcafb9a..368a0f6c 100644 --- a/src/Pages.jl +++ b/src/Pages.jl @@ -72,14 +72,19 @@ function Page( route::Union{Route,String}; if isempty(_pages) push!(_pages, page) else - for i in eachindex(_pages) + new_page = true + replaced = false + for i in reverse(eachindex(_pages)) if _pages[i].route.path == route.path && _pages[i].route.method == route.method + # if already replaced then delete the duplicate + replaced && deleteat!(_pages, i) Router.delete!(Router.routename(_pages[i].route)) _pages[i] = page - else - push!(_pages, page) + new_page = false + replaced = true end end + new_page && push!(_pages, page) end Router.route(route)