Skip to content

Commit

Permalink
update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
smtdfc committed Mar 10, 2024
1 parent fcb1952 commit 70d92f5
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/modules/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,38 @@ export class TurtleRouterModule {
}

async matches(url) {
let u = new URL(url, window.location.origin)
url = u.pathname
let u = new URL(url, window.location.origin)
url = u.pathname
for (let j = 0; j < Object.keys(this.routes).length; j++) {
let route = Object.keys(this.routes)[j]
let configs = this.routes[route]
let routeSplited = route.split("/")
let urlSplited = url.split("/")
let passed = true
let params = {}
if (urlSplited.length != routeSplited.length) {
passed = false
} else {
for (let i = 0; i < routeSplited.length; i++) {
if (urlSplited[i] === undefined) {
passed = false

for (let i = 0; i < routeSplited.length; i++) {
}

if (urlSplited[i] === undefined) {
passed = false

}
if (routeSplited[i] == "*") {
continue
}

if (routeSplited[i] == "*") {
continue
}
if (routeSplited[i][0] == ":") {
let name = routeSplited[i].substring(1, routeSplited[i].length)
params[name] = urlSplited[i]
continue
}

if (routeSplited[i][0] == ":") {
let name = routeSplited[i].substring(1, routeSplited[i].length)
params[name] = urlSplited[i]
continue
}
if (routeSplited[i] != urlSplited[i]) {
passed = false

if (routeSplited[i] != urlSplited[i]) {
passed = false

}
}
}

Expand Down Expand Up @@ -107,7 +109,7 @@ export class TurtleRouterModule {
} else {
path = path.slice(2)
}

window.addEventListener("hashchange", function() {
if (started) {
let path = window.location.hash
Expand All @@ -118,10 +120,10 @@ export class TurtleRouterModule {
}
this.matches(path)
}

}.bind(this))



this.matches(path)
started = true
Expand Down

0 comments on commit 70d92f5

Please sign in to comment.