History

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

Thibaut Courouble committed 9 years ago

Commit f5194d31 parent 06785c02 files · +17 −3Browse files

Unified · Split

2 files
  1. assets/javascripts/app/router.coffee +11 −2
  2. assets/javascripts/lib/page.coffee +6 −1
assets/javascripts/app/router.coffee+11−2
@@ -66,14 +66,23 @@ class app.Router · 65 unmodified lines
6666
6767 entry: (context, next) ->
6868 doc = app.docs.findBySlug(context.params.doc)
69+ return next() unless doc
70+ path = context.params.path
71+ hash = context.hash
6972
70− if entry = doc?.findEntryByPathAndHash(context.params.path, context.hash)
73+ if entry = doc.findEntryByPathAndHash(path, hash)
7174 context.doc = doc
7275 context.entry = entry
7376 @triggerRoute 'entry'
7477 return
78+ else if path.slice(-6) is '/index'
79+ path = path.substr(0, path.length - 6)
80+ return entry.fullPath() if entry = doc.findEntryByPathAndHash(path, hash)
7581 else
76− return next()
82+ path = "#{path}/index"
83+ return entry.fullPath() if entry = doc.findEntryByPathAndHash(path, hash)
84+
85+ return next()
7786
7887 root: ->
7988 return '/' if app.isSingleDoc()
assets/javascripts/lib/page.coffee+6−1
@@ -53,7 +53,12 @@ page.replace = (path, state, skipDispatch, init) -> · 52 unmodified lines
5353 context = new Context(path, state or currentState)
5454 context.init = init
5555 currentState = context.state
56− page.dispatch(context) unless skipDispatch
56+ result = page.dispatch(context) unless skipDispatch
57+ if result
58+ context = new Context(result)
59+ context.init = init
60+ currentState = context.state
61+ page.dispatch(context)
5762 context.replaceState()
5863 updateCanonicalLink()
5964 track() unless skipDispatch

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t