Skip to content

Commit

Permalink
Merge branch 'master' of github.com:railsware/js-routes
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Oct 17, 2024
2 parents 7492897 + 87f8955 commit 40d9a53
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

[![CI](https://github.com/railsware/js-routes/actions/workflows/ci.yml/badge.svg)](https://github.com/railsware/js-routes/actions/workflows/ci.yml)

Generates javascript file that defines all Rails named routes as javascript helpers
Generates javascript file that defines all Rails named routes as javascript helpers:

``` js
import { root_path, api_user_path } from './routes';

root_path() # => /
api_user_path(25, include_profile: true, format: 'json') // => /api/users/25.json?include_profile=true
```

[More Examples](#usage)

## Intallation

Expand Down Expand Up @@ -459,33 +468,25 @@ console.log(routes.inbox_path); // OK, only `inbox_path` is included in the bund
console.log(Object.keys(routes)); // forces bundler to include all exports, breaking tree shaking
```

### Exclude option
### Exclude/Include options

Split your routes into multiple files related to each section of your website like:

``` javascript
// admin-routes.js.erb
<%= JsRoutes.generate(include: /^admin_/) %>
// app-routes.js.erb
<%= JsRoutes.generate(exclude: /^admin_/) %>
``` ruby
JsRoutes.generate!('app/javascript/admin-routes.js', include: /^admin_/) %>
JsRoutes.generate!('app/javascript/app-routes.js', exclude: /^admin_/) %>
```

## Advantages over alternatives

There are some alternatives available. Most of them has only basic feature and don't reach the level of quality I accept.
Advantages of this one are:

* Rails 4,5,6 support
* Actively maintained
* [ESM Tree shaking](https://webpack.js.org/guides/tree-shaking/) support
* Rich options set
* Full rails compatibility
* Support Rails `#to_param` convention for seo optimized paths
* Well tested

#### Thanks to [contributors](https://github.com/railsware/js-routes/contributors)

#### Have fun


## License
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Frailsware%2Fjs-routes.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Frailsware%2Fjs-routes?ref=badge_large)

0 comments on commit 40d9a53

Please sign in to comment.