diff --git a/tremolo/routes.py b/tremolo/routes.py index 3b38090..cc8c1d5 100644 --- a/tremolo/routes.py +++ b/tremolo/routes.py @@ -24,7 +24,6 @@ def __init__(self): self[1] = [ (b'^/+(?:\\?.*)?$', handlers.index, getoptions(handlers.index), {}) ] - self[-1] = [] def add(self, func, path='/', kwargs=None, **options): if not kwargs: @@ -47,10 +46,10 @@ def add(self, func, path='/', kwargs=None, **options): key = bytes([len(parts)]) + parts[0] pattern = b'^/+%s(?:/+)?(?:\\?.*)?$' % path - if key != 1 and key in self: - self[key].append((pattern, func, kwargs, options)) - else: + if key not in self or self[key][0][1] is handlers.index: self[key] = [(pattern, func, kwargs, options)] + else: + self[key].append((pattern, func, kwargs, options)) def compile(self, executor=None): for key in self: