Once router is successfully integrated. router
is available inside component as global variable.
router is same variable which was provided while initiating the mahal-router
in plugin. It has different props and api to help you with different scenario.
import { Component, reactive } from "mahal";
export default class extends Component{
onInit(){
this.router = this.global.router;
}
}
router has follwing props and api -
goto
allows you to change a route by route object.
const router = this.global.router;
router.goto({
name:'home',
query:{
},
param:{
}
})
The route has following options -
gotoPath
allows you to change a route by path. It internally uses goto
.
const router = this.global.router;
router.gotoPath("/")
currentRoute
is a prop on router which returns the information about current route.
const router = this.global.router;
router.currentRoute;
It can be shorthand to route
.
const route = this.global.route;
It can be used to get the params
or query
from the current route.
const route = this.global.route;
const id = route.query.id;
const userId = route.param.userId;
back
can be used to go to back route.
const router = this.global.router;
router.back();
go
can be used to go to route by delta(number).
const router = this.global.router;
router.go(-1);