You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The new hook _onBeforeRoute() enables the integration of any router:
// _default.page.route.jsimport{routeMatchesUrl}from'some-router-library'export{_onBeforeRoute}function_onBeforeRoute(pageContext){letmatch=nullpageContext._pageRoutes.forEach(({pageId, pageRouteFile, filesystemRoute})=>{if(match){return}if(pageRouteFile){constpageRoute=pageRouteFile.fileExports.default// Does `.page.route.js` export a Route String or Route Function?if(typeofpageRoute==='string'){// We can use any logic we want, e.g. `some-router-library` could be Vue Routerif(routeMatchesUrl(pageRoute,pageContext.url)){match=pageIdreturn}}if(typeofpageRoute==='function'){// We can also handle Route Functions// ...}}// We can even implement something like Next.js' FileSystem parameterized routing `pages/product/[id].page`if(routeMatchesUrl(filesystemRoute,pageContext.url)){match=pageIdreturn}// Or simply non-parameterized FileSystem Routing:if(filesystemRoute===pageContext.url){match=pageIdreturn}})// Setting `pageContext._pageId` to `null` means 404.// Not setting or setting `pageContext._pageId` to `undefined` makes `vite-plugin-ssr` apply its usual// routing mechanism.return{pageContext: {_pageId: match}}}
The new hook
_onBeforeRoute()
enables the integration of any router:Users can "install plugins" simply by doing:
@gryphonmyers Is that enough for Vue Router? Am I missing something?
The text was updated successfully, but these errors were encountered: