Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Use your AdonisJs routes in your Inertia.js application

License

NotificationsYou must be signed in to change notification settings

izzyjs/route

Repository files navigation

GitHub Actions StatusCoverage StatusGitHub issuesGitHub pull requestsnpm versionLicense

Use your AdonisJs routes in JavaScript.

This package provides a JavaScriptroute() 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 theroute() 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 theadonisrc.ts file to register the() => import('@izzyjs/route/dev_hook') ononDevServerStarted array list.

{// rest of adonisrc.ts fileunstable_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 theroute() 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 useroute() on the client side to generate URLs for named routes.

import{route}from'@izzyjs/route/client'consturl=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'consturl=route('users.show',{id:'1'})// /users/1url.method// GETurl.pattern// /users/:idurl.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/1route().current()// /users/1route().current('/users/1')// trueroute().current('/users/2')// falseroute().current('users.*')// true

Has

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

// start/routes.tsimportrouterfrom'@adonisjs/core/services/router'constusersConstroller=()=>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')// trueroute().has('users.*')// trueroute().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 ourContribution Guidelines.

Code of Conduct

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

License

MIT License ©IzzyJs

Built with ❤︎ byWalaff Fernandes

[8]ページ先頭

©2009-2025 Movatter.jp