File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed
Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 11import WarpRouter from 'warp-router'
22import { Configuration } from "../../src/Configuration" ;
33import { Route } from "../../src/Route" ;
4+ import { myFunction } from "./page2" ;
45
56function createDemo ( ) {
67 const configuration = new Configuration ( )
78 configuration . defaultRoute = ""
89 const router = new WarpRouter ( '.container' , configuration )
910 let routes : Map < string , Route > = new Map ( )
10- routes . set ( "" , new Route ( function ( ) {
11+ routes . set ( "" , new Route ( ( ) : string => {
1112 return "This is the home page"
1213 } ) )
13- routes . set ( "#page1" , new Route ( ( ) => {
14- router . hostElement . innerHTML = `<p>This content was generated by a routing function</p>`
14+ routes . set ( "#page1" , new Route ( ( ) : void => {
15+ router . hostElement . innerHTML = `<p>This content was generated by a routing function page 1</p>`
16+ }
17+ ) )
18+ routes . set ( "#page2" , new Route ( ( ) : void => {
19+ myFunction ( router . hostElement )
1520 }
1621 ) )
1722
1823 router . setRoutes ( routes )
24+
25+
26+ router . attach ( )
1927}
2028
2129createDemo ( )
Original file line number Diff line number Diff line change 1+ export const myFunction = ( hostElement ) => {
2+ hostElement . innerHTML = `
3+ <p>This content was generated by a routing function page 2</p>
4+ <button id="page2btn">This button will do something</button>
5+ `
6+
7+ function addListeners ( ) {
8+ document . querySelector ( '#page2btn' ) . addEventListener ( 'click' , function ( ) {
9+ alert ( "It workew" )
10+ } )
11+ }
12+
13+ addListeners ( )
14+ }
Original file line number Diff line number Diff line change @@ -6,4 +6,8 @@ export class Route {
66 constructor ( public routingFunction : RoutingFunction , public context = null ) {
77
88 }
9+
10+ run ( ) {
11+ return this . routingFunction ( )
12+ }
913}
You can’t perform that action at this time.
0 commit comments