Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
smtdfc committed Aug 1, 2023
1 parent bdae901 commit 600cdf8
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ window.addEventListener("popstate", function(e) {
}
})

export function redirect(path,replace=false) {
function redirect(path,replace=false) {
if (Router.type == "hash") {

if(replace){
Expand All @@ -192,7 +192,7 @@ export function redirect(path,replace=false) {
}
}

export function initRouter(configs) {
function initRouter(configs) {
Router.element = configs.element ? document.querySelector(configs.element) : document.createElement("div")
if (!Router.element) {
throw `Invalid element ${configs.element}`
Expand Down Expand Up @@ -230,11 +230,11 @@ class LinkComponent extends HTMLElement{
}

window.customElements.define("link-to",LinkComponent)
export function setRouterEventListener(name,callback){
function setRouterEventListener(name,callback){
Router.events[name] = callback
}

export function startRouter(){
function startRouter(){
if (Router.type == "hash") {
let hash = window.location.hash
resolveRoute(hash.slice(1))
Expand All @@ -244,4 +244,11 @@ export function startRouter(){
resolveRoute(path)
}

}

export const RouterControl = {
init:initRouter,
start:startRouter,
redirect:redirect,
on:setRouterEventListener,
}

0 comments on commit 600cdf8

Please sign in to comment.