1
0
Fork 0
mirror of https://github.com/Findus23/RainbowRoad.git synced 2024-09-19 16:03:52 +02:00
RainbowRoad/src/router.ts

46 lines
1 KiB
TypeScript
Raw Normal View History

2022-08-27 17:51:07 +02:00
import Navigo, {NavigateOptions} from "navigo";
2023-04-22 00:33:07 +02:00
import {matomo} from "./matomo";
import {locationAlias} from "matomo-lite-tracker/src/aliases";
2022-08-27 17:51:07 +02:00
class CustomNavigo extends Navigo {
navigateReplace(to: string, options?: NavigateOptions) {
if (typeof options === "undefined") {
options = {}
}
options.historyAPIMethod = "replaceState"
this.navigate(to, options);
}
}
export const router = new CustomNavigo("/")
2022-08-26 00:10:59 +02:00
2023-04-22 00:33:07 +02:00
router.hooks({
after(m) {
if (matomo) {
matomo.customURL = locationAlias.protocol + '//' +
locationAlias.hostname + "/" + m.url
2024-04-06 23:40:31 +02:00
matomo.trackPageview()
2023-04-22 00:33:07 +02:00
}
}
})
2022-12-11 20:47:19 +01:00
2022-08-26 00:10:59 +02:00
// router.on("/Wien", () => {
// map.setView(viewFromArea(Wien))
//
// })
// router.on("/Ober%C3%B6sterreich", () => {
// map.setView(viewFromArea(areas.OOE))
//
//
// })
// redirect(router, "/", "/Wien")
2022-08-15 15:54:18 +02:00
2022-08-27 17:51:07 +02:00
export function redirect(router: CustomNavigo, from: string, to: string) {
2022-08-15 15:54:18 +02:00
router.on(from, () => {
2022-08-27 17:51:07 +02:00
router.navigateReplace(to)
2022-08-15 15:54:18 +02:00
})
}