Socket
Book a DemoInstallSign in
Socket

webpacker-routes

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpacker-routes

0.1.5
bundlerRubygems
Version published
Maintainers
1
Created
Source

Webpacker::Routes

Webpacker Routes allows you to import Rails routes in your Webpacker javascript.

Installation

Add this line to your application's Gemfile:

gem 'webpacker-routes'

And then execute:

$ bundle
$ bundle exec rails webpacker:install:routes

Usage

Import individual routes from any Webpacker-compiled file:

import { root_path, root_url } from 'routes'
import { engine_path } from 'routes/engine_name'

root_path()
// /

root_path({ foo: 'bar' })
// /?foo=bar

root_url({ host: 'https://example.com' })
// https://example.com/

root_url({ host: 'https://example.com', bar: 'baz' })
// https://example.com/?bar=baz

root_url({
  anchor: 'abc',
  host: 'example.com',
  params: {
    foo: 'bar'
  },
  port: 3000,
  protocol: 'https',
  relative_url_root: '/rel',
  trailing_slash: true,
  bar: 'baz'
})
// https://example.com:3000/rel/?bar=baz&foo=bar#abc

The routes file is generated when Rails starts, including during webpacker:compile (or assets:precompile). In development, routes will be updated when a file changes and a request is processed.

To generate routes manually, run:

$ bundle exec rails webpacker:routes:generate

Options

  • config.webpacker.routes.default_url_options - defaults used for generating urls. These are merged with Rails.application.default_url_options. Default: {}
  • config.webpacker.routes.camel_case - convert route names to camel case. Default: false

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 25 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.