Navigation Router
The only difference in Framework7-React is that in React.js we are already composing our application with React components, so we need to map our Pages (React components) to the routes. It can be done by passing React component in property of the route. Here’s a basic example:
// home.jsx
export default () => (
<Page name="home">
<Navbar title="Home Page" />
...
<Link href="/about/">About Page</Link>
<Link href="/login/">Login Page</Link>
</Page>
)
// about.jsx
export default () => (
<Page name="about">
{/* Page content */}
...
)
Check the full Routes Documentation to know about all possible routes options, how to use , Routable Tabs and .
First of all, all route params will be automatically passed as props to component, e.g.
// route with params
{
path: '/blog/:postId/comments/:commentId/',
component: BlogPost,
}
So if we navigate by /blog/45/comments/122/
URL, then the following data will be passed to props:
{
postId: '45',
commentId: '122',
}
And finally, props can be passed dynamically to route component when we navigate with API:
this.$f7router.navigate('/some-page/', {
props: {
}
})
With Webpack it is possible to load page components on demand, it is possible with F7’s async route, for example:
{
path: '/about/',
async(routeTo, routeFrom, resolve, reject) {
// dynamic import component; returns promise
const reactComponent = () => import('./pages/about.jsx');
// resolve promise
reactComponent().then((rc) => {
// resolve with component
resolve({ component: rc.default })
});
} ,
},
Please note, that $f7route
and component properties are only available inside of custom page components that you load according to routes. In parent components (like in View, or where you init your React app instance) and in child components they are not accessible. So in this case use access to initialized View Instance, e.g. $f7.views.main.router