Routing
Basic usage
import { WebComponent } from '@webcomp/core';
import { Router } from '@webcomp/router';
class MyElement extends WebComponent{
componentDidMount = () => {
Router.on('/profile/:id', this.handleRouteChange);
}
handleRouteChange = (url) => {
console.log('Route changed! ID:', url.params.id); // "Route changed! ID: 123"
}
changeRoute = () => {
Router.push('/profile/123');
}
render() {
return <button onClick={this.changeRoute}>Change Route</button>
}
}Router Methods and Properties
Router.mode
Router.modeRouter.root
Router.root`on(route, handlerFunction, persist)`
`on(route, handlerFunction, persist)`removeHandler(id)
removeHandler(id)flushHandlers()
flushHandlers()dangerouslyFlushRouter()
dangerouslyFlushRouter()push(path)
replace(path)
replace(path)Routerize decorator
Routerize decorator<Route /> Component
Shallow routes
Advanced Usage
Custom Routers
Custom router options
Routerizing with custom router
Using custom routers with <Route />
<Route />Last updated
Was this helpful?