-
-
Notifications
You must be signed in to change notification settings - Fork 926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document Title doesn't change with m.route.set options #2600
Comments
Known issue with no intention to fix. This is up to the browsers to implement, not us. It's worth noting that not all browsers ignore it this blatantly. If anything, I'm tempted to drop support for the |
Well, sure, the specs say: |
@agentx-cgn If you really want a true drop-in workaround, just write a helper like this: function setRoute(path, params, opts) {
var prev = document.title
try {
if (opts && opts.title) document.title = opts.title
m.route.set(path, params, opts)
} finally {
if (opts && opts.title) document.title = prev
}
} That should likely be sufficient for your needs, as browsers I believe should honor that. If that doesn't work (as in function setRoute(path, params, opts) {
if (opts && opts.title) {
var prev = document.title
// This listener is intentionally capturing, so it precedes
// Mithril's own listener
window.addEventListener("popstate", function handler() {
window.removeEventListener("popstate", handler, true)
document.title = prev
}, true)
document.title = opts.title
try {
m.route.set(path, params, opts)
} catch (e) {
handler()
throw e
}
} else {
m.route.set(path, params, opts)
}
} |
Browsers seem to ignore the pushState/replaceState option
title
. As consequence pages in the browser's history are indistinguishable. The workaround is to set the title withdocument.title = 'Your title here'
. Mithril should handle this gracefully and automatically.Discussion: whatwg/html#2174
Solution: https://stackoverflow.com/questions/13955520/page-title-is-not-changed-by-history-pushstate
Version: as of today
The text was updated successfully, but these errors were encountered: