-
Notifications
You must be signed in to change notification settings - Fork 48
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
Keep full url when switching version ? #81
Comments
This feature is already implemented in Material for MkDocs, which you're using. |
Yeah, this is a goal for 2.0, but there are some subtleties I haven't quite worked out, like what to do when the directory structure has changed between versions. In that case, it'd be nice to redirect to the homepage for the specified version, or at least to have a nicer 404 page than we currently have. |
I saw that but it's only in insiders version for now ^^ |
I agree,a nice 404 with a message "this page was not existing in version XXX" would be nice :) |
I have tried your js code, but it seems that it doesn't work, maybe I have got something wrong. I write an another js code and it can work. Just put it here for someone who may need it. (window.onload = function () {
setInterval(function () {
var items = document.querySelectorAll('.md-version__link:not(.changed)');
if (!items.length) return;
var item = document.querySelector(".md-version__current");
if (!item) return;
var version_now = item.innerHTML;
console.log(version_now);
var i = window.location.pathname.indexOf(version_now) + version_now.length + 1;
var pathname = window.location.pathname.slice(i);
for (var item of items) {
item.href += pathname;
item.className += " changed";
console.log(item.innerHTML, "change successfully");
}
}, 100);
})(); |
The way and If the URL isn't valid in the version we're switching to, it just redirects to the default page for that version. I was briefly considering trying to implement this for OTOH, I'm not sure Material's behavior I described above is actually preferable to just redirecting to the same path in the other version and having a reasonable 404 page in case there is no page at that path. |
Using |
This approach also has some downsides (though I don't think they are dealbreakers). Most notably, if the |
Hi,
Thanks for the great tool !
Is there a way to remain on the current page when switching version ?
Example, when I'm on https://megalinter.github.io/v5.0.5/all_linters/ , I would like to land on https://megalinter.github.io/beta/all_linters/ when I switch to beta version, but unfortunately it always brings me back to the root URL
Maybe with a javascript hack ? ( I already do that to rename/reorder versions in the dropdown widget) -> https://github.com/megalinter/megalinter/blob/main/docs/javascripts/version-mike.js
The text was updated successfully, but these errors were encountered: