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 Sep 12, 2024
2 parents d93bf0d + 76d044c commit c73dbf4
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ There are several possible ways to setup JsRoutes:
4. [Sprockets](#sprockets) - Legacy
* Deprecated and not recommended for modern apps

<div id='quick-start'></div>

### Quick Start
### Quick Start {#quick-start}

Setup [Rack Middleware](https://guides.rubyonrails.org/rails_on_rack.html#action-dispatcher-middleware-stack)
to automatically generate and maintain `routes.js` file and corresponding
Expand Down Expand Up @@ -77,13 +75,10 @@ Add js-routes files to `.gitignore`:
/app/javascript/routes.d.ts
```

<div id='webpacker'></div>

### Webpacker ERB loader
### Webpacker ERB loader {#webpack}

**IMPORTANT**: the setup doesn't support IDE autocompletion with [Typescript](https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html)


#### Use a Generator

Run a command:
Expand Down Expand Up @@ -133,17 +128,15 @@ Create routes file `app/javascript/routes.js.erb`:
<%= JsRoutes.generate() %>
```

Use routes wherever you need them:
Use routes wherever you need them:

``` javascript
import {post_path} from 'routes.js.erb';

alert(post_path(2));
```

<div id='advanced-setup'></div>

### Advanced Setup
### Advanced Setup {#advanced-setup}

In case you need multiple route files for different parts of your application, there are low level methods:

Expand Down Expand Up @@ -208,11 +201,9 @@ class AdvancedJsRoutesMiddleware < JsRoutes::Middleware
end
```

<div id='definitions'></div>

#### Typescript Definitions
#### Typescript Definitions {#definitions}

JsRoutes has typescript support out of the box.
JsRoutes has typescript support out of the box.

Restrictions:

Expand All @@ -224,16 +215,14 @@ More advanced setup would involve calling manually:

``` ruby
JsRoutes.definitions! # to output to file
# or
# or
JsRoutes.definitions # to output to string
```

Even more advanced setups can be achieved by setting `module_type` to `DTS` inside [configuration](#module_type)
which will cause any `JsRoutes` instance to generate defintions instead of routes themselves.

<div id="sprockets"></div>

### Sprockets (Deprecated)
### Sprockets (Deprecated) {#sprockets}

If you are using [Sprockets](https://github.com/rails/sprockets-rails) you may configure js-routes in the following way.

Expand Down

0 comments on commit c73dbf4

Please sign in to comment.