-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from AliMD/feat/router
Router outlet and new API
- Loading branch information
Showing
5 changed files
with
260 additions
and
18 deletions.
There are no files selected for viewing
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,9 +1,45 @@ | ||
import {initialRouter, routeChangeSignal} from '@alwatr/router'; | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import {router} from '@alwatr/router'; | ||
import type {Route, RoutesConfig} from '@alwatr/router'; | ||
|
||
initialRouter(); | ||
/** | ||
* Initial and config the Router. | ||
*/ | ||
router.initial(); | ||
|
||
routeChangeSignal.addListener((route) => { | ||
console.info('routeChangeSignal', route); | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
document.querySelector('textarea')!.value = JSON.stringify(route, null, 2); | ||
}); | ||
const routes: RoutesConfig = { | ||
map: (route: Route): string | undefined => route.sectionList[0]?.toString(), | ||
|
||
list: { | ||
'about': { | ||
render: (): string => '<h1>About Page</h1>', | ||
}, | ||
'product-list': { | ||
render: (): string => '<h1>Product List ...</h1>', | ||
}, | ||
'contact': { | ||
render: (): string => '<h1>Product Page</h1>', | ||
}, | ||
|
||
'home': { | ||
render: (): string => '<h1>Home Page</h1>', | ||
}, | ||
'404': { | ||
render: (): string => '<h1>404 Not Found!</h1>', | ||
}, | ||
}, | ||
}; | ||
|
||
/** | ||
* Your render process, can be lit-element requestUpdate or any other framework request render method. | ||
*/ | ||
function render(): void { | ||
console.info('render'); | ||
document.querySelector('textarea')!.value = JSON.stringify(router.currentRoute, null, 2); | ||
document.querySelector('.render')!.innerHTML = router.outlet(routes) as string; | ||
} | ||
|
||
/** | ||
* Request update in route change. | ||
*/ | ||
router.signal.addListener(render); |
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