Skip to content

Routing Guide

Setup

ts
import { createRouter } from 'nexa-router'
import Home from './Home.nexa'
import About from './About.nexa'

const router = createRouter({
  routes: [
    { path: '/', component: Home },
    { path: '/about', component: About },
    { path: '*', component: NotFound },
  ],
  mode: 'history',
})
ts
router.navigate('/about')
router.currentPath.value   // reactive signal
router.currentRoute.value  // matched route
ts
import { Link } from 'nexa-router'

// Use in render function
Link({ to: '/about' }, { navigate: router.navigate })

Route Guards

ts
import { createGuards } from 'nexa-router'

const guards = createGuards()
guards.beforeEach((to, from) => {
  return isAuthenticated || to === '/login'
})
await guards.runGuards('/admin', '/')

Released under the MIT License.