Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davishmcclurg/webpacker-routes
Import Rails routes in your Webpacker javascript.
https://github.com/davishmcclurg/webpacker-routes
javascript rails ruby webpack webpacker
Last synced: 3 days ago
JSON representation
Import Rails routes in your Webpacker javascript.
- Host: GitHub
- URL: https://github.com/davishmcclurg/webpacker-routes
- Owner: davishmcclurg
- License: mit
- Created: 2018-10-14T21:11:11.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-10-16T02:21:34.000Z (3 months ago)
- Last Synced: 2024-10-19T10:25:03.605Z (3 months ago)
- Topics: javascript, rails, ruby, webpack, webpacker
- Language: Ruby
- Homepage:
- Size: 1.47 MB
- Stars: 10
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# Webpacker::Routes
Webpacker Routes allows you to import Rails routes in your Webpacker javascript.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'webpacker-routes'
```And then execute:
```bash
$ bundle
$ bundle exec rails webpacker:install:routes
```## Usage
Import individual routes from any Webpacker-compiled file:
```javascript
import { root_path, root_url } from 'routes'
import { engine_path } from 'routes/engine_name'root_path()
// /root_path({ foo: 'bar' })
// /?foo=barroot_url({ host: 'https://example.com' })
// https://example.com/root_url({ host: 'https://example.com', bar: 'baz' })
// https://example.com/?bar=bazroot_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:
```bash
$ 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](https://opensource.org/licenses/MIT).