Socket
Socket
Sign inDemoInstall

@embroider/router

Package Overview
Dependencies
423
Maintainers
9
Versions
343
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@embroider/router

Lazy loading router


Version published
Maintainers
9
Weekly downloads
25,323
increased by20.75%

Weekly downloads

Readme

Source

@embroider/router

A tiny extension to the stock Ember Router that detects the presence of lazy route bundles and loads them when needed.

Compatibility

  • Ember.js v3.28 or above
  • Ember CLI v3.28 or above
  • Node.js v16 or above

To get code-splitting, your app must build with Embroider. It's safe to use this router in apps that aren't building with Embroider, but it won't do anything.

Limitations

Route "serialize" hook Not Supported

When using lazily-loaded routes, the serialize hook on Route is not supported, because this would require us to load a Route when someone is only linking to it, not actually visiting it.

Route Unit Tests may need to be updated

Once you enable lazy loading of routes, any Route unit tests that try to lookup('route:your-route-name') can fail because the route is not necessarily loaded. You can adjust your tests to explicitly import and register the Route:

import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
+ import ExampleRoute from 'your-app/routes/example';

module('Unit | Route | example', function (hooks) {
  setupTest(hooks);

+ hooks.beforeEach(function () {
+   this.owner.register('route:example', ExampleRoute);
+ });

  test('it exists', function (assert) {
    let route = this.owner.lookup('route:example');
    assert.ok(route);
  });
});

Installation

ember install @embroider/router

In your router.js file, import our router instead of the stock one:

-import EmberRouter from '@ember/routing/router';
+import EmberRouter from '@embroider/router';

Notes on usage with pods

If you use the pod file layout for your routes, you have to make sure to set a non-undefined podModulePrefix in your config/environment.js. podModulePrefix: '' is also allowed. Otherwise, your pod routes will not be picked up by Embroider.

License

This project is licensed under the MIT License.

Keywords

FAQs

Last updated on 28 Nov 2023

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc