Skip to content
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

History plugin fixes and new option adding #5665

Merged
merged 4 commits into from
Apr 26, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/modules/history/history.js
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ export default function History({ swiper, extendParams, on }) {
root: '',
replaceState: false,
key: 'slides',
keepQuery: false,
},
});

@@ -58,6 +59,9 @@ export default function History({ swiper, extendParams, on }) {
} else if (!location.pathname.includes(key)) {
value = `${key}/${value}`;
}
if (swiper.params.h.keepQuery) {
VahanMargaryan marked this conversation as resolved.
Show resolved Hide resolved
value += location.search;
}
const currentState = window.history.state;
if (currentState && currentState.value === value) {
return;
@@ -86,7 +90,7 @@ export default function History({ swiper, extendParams, on }) {

const setHistoryPopState = () => {
paths = getPathValues(swiper.params.url);
scrollToSlide(swiper.params.speed, swiper.paths.value, false);
scrollToSlide(swiper.params.speed, paths.value, false);
};

const init = () => {
14 changes: 14 additions & 0 deletions src/types/modules/history.d.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,13 @@ export interface HistoryMethods {}
export interface HistoryEvents {}

export interface HistoryOptions {
/**
* Enables History Plugin.
*
* @default false
*/
enabled?: boolean;

/**
* Swiper page root, useful to specify when you use Swiper history mode not on root website page.
* For example can be `https://my-website.com/` or `https://my-website.com/subpage/` or `/subpage/`
@@ -26,4 +33,11 @@ export interface HistoryOptions {
* @default 'slides'
*/
key?: string;

/**
* Keep query parameters when changing browser url.
*
* @default false
*/
keepQuery?: boolean;
}