Skip to content

Commit 0e9ffc4

Browse files
kfuledead-claudia
authored andcommitted
router: calls route.set instead of setPath when fallback
1 parent b304503 commit 0e9ffc4

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

api/router.js

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module.exports = function($window, mountRedraw) {
8080

8181
function reject(e) {
8282
console.error(e)
83-
setPath(fallbackRoute, null, {replace: true})
83+
route.set(fallbackRoute, null, {replace: true})
8484
}
8585

8686
loop(0)
@@ -124,7 +124,7 @@ module.exports = function($window, mountRedraw) {
124124
if (path === fallbackRoute) {
125125
throw new Error("Could not resolve default route " + fallbackRoute + ".")
126126
}
127-
setPath(fallbackRoute, null, {replace: true})
127+
route.set(fallbackRoute, null, {replace: true})
128128
}
129129
}
130130

@@ -138,26 +138,6 @@ module.exports = function($window, mountRedraw) {
138138
}
139139
}
140140

141-
function setPath(path, data, options) {
142-
if (lastUpdate != null) {
143-
options = options || {}
144-
options.replace = true
145-
}
146-
lastUpdate = null
147-
148-
path = buildPathname(path, data)
149-
if (ready) {
150-
fireAsync()
151-
var state = options ? options.state : null
152-
var title = options ? options.title : null
153-
if (options && options.replace) $window.history.replaceState(state, title, route.prefix + path)
154-
else $window.history.pushState(state, title, route.prefix + path)
155-
}
156-
else {
157-
$window.location.href = route.prefix + path
158-
}
159-
}
160-
161141
function route(root, defaultRoute, routes) {
162142
if (!root) throw new TypeError("DOM element being rendered to does not exist.")
163143

@@ -187,7 +167,25 @@ module.exports = function($window, mountRedraw) {
187167
mountRedraw.mount(root, RouterRoot)
188168
resolveRoute()
189169
}
190-
route.set = setPath
170+
route.set = function(path, data, options) {
171+
if (lastUpdate != null) {
172+
options = options || {}
173+
options.replace = true
174+
}
175+
lastUpdate = null
176+
177+
path = buildPathname(path, data)
178+
if (ready) {
179+
fireAsync()
180+
var state = options ? options.state : null
181+
var title = options ? options.title : null
182+
if (options && options.replace) $window.history.replaceState(state, title, route.prefix + path)
183+
else $window.history.pushState(state, title, route.prefix + path)
184+
}
185+
else {
186+
$window.location.href = route.prefix + path
187+
}
188+
}
191189
route.get = function() {return currentPath}
192190
route.prefix = "#!"
193191
route.Link = {

0 commit comments

Comments
 (0)