npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@izzyjs/route

v1.2.0

Published

Use your AdonisJs routes in your Inertia.js application

Downloads

310

Readme

@izzyjs/route

GitHub Actions Status Coverage Status GitHub issues GitHub pull requests npm version License

Use your AdonisJs routes in JavaScript.

This package provides a JavaScript route() function that can be used to generate URLs for named routes defined in an AdonisJs application.

Installation

Install and configure the package using the following command :

node ace add @izzyjs/route

Configuration

To use the route() function in your JavaScript applications, you need to follow these steps:

Command

You can run a command to generate the route definitions from @izzyjs/routes with:

node ace izzy:routes

These type definitions are only needed in a development environment, so they can be generated automatically in the next step.

Assemble Hook

Add the following line to the adonisrc.ts file to register the () => import('@izzyjs/route/dev_hook') on onDevServerStarted array list.

{
  // rest of adonisrc.ts file
  unstable_assembler: {
    onBuildStarting: [() => import('@adonisjs/vite/build_hook')],
    onDevServerStarted: [() => import('@izzyjs/route/dev_hook')] // Add this line,
  }
}

View Helper

Add edge plugin in entry view file @routes to use the route() into javascript.

// resources/views/inertia_layout.edge

<!doctype html>
<html>
  <head>
    // rest of the file 
    @routes() // Add this line
    // rest of the file
  </head>

  <body>
    @inertia()
  </body>
</html>

Usage

Now that we've followed all the steps, we're ready to use route() on the client side to generate URLs for named routes.

import { route } from '@izzyjs/route/client'

const url = route('users.show', { id: '1' }) // /users/1

Route

Is a callback class with a parameter for route(), with information about the method, partern and path itself.

import { route } from '@izzyjs/route/client'

const url = route('users.show', { id: '1' }) // /users/1

url.method // GET
url.pattern // /users/:id
url.path // /users/1

Routes

Is a callback class withoout a parameter for route(), with information about the method, partern and path itself.

Current

The current method returns the current URL of the page or the URL of the page that the user is currently on.

import { route } from '@izzyjs/route/client'

// current /users/1

route().current() // /users/1
route().current('/users/1') // true
route().current('/users/2') // false
route().current('users.*') // true

Has

The has method returns a boolean value indicating whether the named route exists in the application.

// start/routes.ts

import router from '@adonisjs/core/services/router'

const usersConstroller = () => import('#app/controllers/users_controller')

router.get('/users', [usersConstroller, 'index']).as('users.index')
router.get('/users/:id', [usersConstroller, 'show']).as('users.show')
import { route } from '@izzyjs/route/client'

route().has('users.show') // true
route().has('users.*') // true
route().has('dashboard') // false

Params

The params method returns the parameters of the URL of the page that the user is currently on.

import { route } from '@izzyjs/route/client'

route().params() // { id: '1' }

These features enable seamless integration of AdonisJs routing within your JavaScript applications, enhancing flexibility and maintainability. By leveraging route(), you can easily manage and navigate your application routes with ease, ensuring a smooth user experience.

Contributing

Thank you for being interested in making this package better. We encourage everyone to help improve this project with new features, bug fixes, or performance improvements. Please take a little bit of your time to read our guide to make this process faster and easier.

Contribution Guidelines

To understand how to submit an issue, commit and create pull requests, check our Contribution Guidelines.

Code of Conduct

We expect you to follow our Code of Conduct. You can read it to understand what kind of behavior will and will not be tolerated.

License

MIT License © IzzyJs