-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a4741e
commit a2b718b
Showing
7 changed files
with
428 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { IPorpoiseRouter } from "../components/p-router.js"; | ||
import { IRouteDescriptor } from "../internals/api.js"; | ||
|
||
export function createRouter(target: string, routes: Record<string, string | IRouteDescriptor>) { | ||
export function createRouter(target: string, routes: IRouteDescriptor[]) { | ||
const routerNode = document.querySelector(`p-router[name="${target}"]`) as IPorpoiseRouter; | ||
|
||
if (routerNode) { | ||
routerNode.configure(routes); | ||
} | ||
else console.error(`Could not find <porpoise-router name="${target}"></porpoise-router> in the DOM.`); | ||
else console.error(`Could not find <p-router name="${target}"></p-router> in the DOM.`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
export interface ICurrentRoute { | ||
path: string, | ||
params: Record<string, string> | ||
} | ||
|
||
export interface IRouteDescriptor { | ||
path: string | ||
element: string, | ||
props?: Record<string, string> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { match } from "./path-parser.js"; | ||
|
||
export function matchPath(specifier: string, rawPath: string) { | ||
// Catch-all route: | ||
if (specifier === "*") { | ||
return { doesMatch: true, params: null } | ||
} | ||
|
||
// Parse the path: | ||
else { | ||
const matchData = match(specifier, { decode: decodeURIComponent })((rawPath)); | ||
return { | ||
doesMatch: matchData !== false, | ||
params: (matchData as any).params || null | ||
} | ||
} | ||
} |
Oops, something went wrong.