Add automatic/fallback redirection for URLs with missing or incorrect trailing slash

pull/667/merge
Thibaut Courouble 7 years ago
parent 06785c0df5
commit f5194d35bf

@ -66,13 +66,22 @@ class app.Router
entry: (context, next) -> entry: (context, next) ->
doc = app.docs.findBySlug(context.params.doc) doc = app.docs.findBySlug(context.params.doc)
return next() unless doc
path = context.params.path
hash = context.hash
if entry = doc?.findEntryByPathAndHash(context.params.path, context.hash) if entry = doc.findEntryByPathAndHash(path, hash)
context.doc = doc context.doc = doc
context.entry = entry context.entry = entry
@triggerRoute 'entry' @triggerRoute 'entry'
return return
else if path.slice(-6) is '/index'
path = path.substr(0, path.length - 6)
return entry.fullPath() if entry = doc.findEntryByPathAndHash(path, hash)
else else
path = "#{path}/index"
return entry.fullPath() if entry = doc.findEntryByPathAndHash(path, hash)
return next() return next()
root: -> root: ->

@ -53,7 +53,12 @@ page.replace = (path, state, skipDispatch, init) ->
context = new Context(path, state or currentState) context = new Context(path, state or currentState)
context.init = init context.init = init
currentState = context.state currentState = context.state
page.dispatch(context) unless skipDispatch result = page.dispatch(context) unless skipDispatch
if result
context = new Context(result)
context.init = init
currentState = context.state
page.dispatch(context)
context.replaceState() context.replaceState()
updateCanonicalLink() updateCanonicalLink()
track() unless skipDispatch track() unless skipDispatch

Loading…
Cancel
Save