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) ->
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.entry = entry
@triggerRoute 'entry'
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
path = "#{path}/index"
return entry.fullPath() if entry = doc.findEntryByPathAndHash(path, hash)
return next()
root: ->

@ -53,7 +53,12 @@ page.replace = (path, state, skipDispatch, init) ->
context = new Context(path, state or currentState)
context.init = init
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()
updateCanonicalLink()
track() unless skipDispatch

Loading…
Cancel
Save