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
66 66
67 entry: (context, next) ->67 entry: (context, next) ->
68 doc = app.docs.findBySlug(context.params.doc)68 doc = app.docs.findBySlug(context.params.doc)
69 return next() unless doc
70 path = context.params.path
71 hash = context.hash
69 72
70 if entry = doc?.findEntryByPathAndHash(context.params.path, context.hash)73 if entry = doc.findEntryByPathAndHash(path, hash)
71 context.doc = doc74 context.doc = doc
72 context.entry = entry75 context.entry = entry
73 @triggerRoute 'entry'76 @triggerRoute 'entry'
74 return77 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)
75 else81 else
76 return next()82 path = "#{path}/index"
83 return entry.fullPath() if entry = doc.findEntryByPathAndHash(path, hash)
84
85 return next()
77 86
78 root: ->87 root: ->
79 return '/' if app.isSingleDoc()88 return '/' if app.isSingleDoc()
assets/javascripts/lib/page.coffee+6−1
@@ -53,7 +53,12 @@ page.replace = (path, state, skipDispatch, init) -> · 52 unmodified lines
53 context = new Context(path, state or currentState)53 context = new Context(path, state or currentState)
54 context.init = init54 context.init = init
55 currentState = context.state55 currentState = context.state
56 page.dispatch(context) unless skipDispatch56 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)
57 context.replaceState()62 context.replaceState()
58 updateCanonicalLink()63 updateCanonicalLink()
59 track() unless skipDispatch64 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