From 07baaafb433677a89c8b8e2eee6a42758964f91d Mon Sep 17 00:00:00 2001 From: Nicholas Cunningham Date: Mon, 26 May 2025 06:14:00 -0600 Subject: [PATCH] fix(react): routing option to library generator (#31328) ## Current Behavior When we try to generate a library with react it fails because `name` is required. ## Expected Behavior This should work out of the box. ## Related Issue(s) Fixes #30721 --- .../src/generators/library/library.spec.ts | 17 +++++++++++++++++ .../react/src/generators/library/library.ts | 1 + 2 files changed, 18 insertions(+) diff --git a/packages/react/src/generators/library/library.spec.ts b/packages/react/src/generators/library/library.spec.ts index 469815a192..4a537d98d5 100644 --- a/packages/react/src/generators/library/library.spec.ts +++ b/packages/react/src/generators/library/library.spec.ts @@ -533,6 +533,23 @@ describe('lib', () => { }); }); + describe('--routing', () => { + it('should be able to generate a library with routing', async () => { + await libraryGenerator(tree, { + ...defaultSchema, + routing: true, + }); + + const content = tree.read('my-lib/src/lib/my-lib.tsx', 'utf-8'); + expect(content).toContain('react-router-dom'); + + expect(content).toMatch(/my-lib root<\/Link>/); + expect(content).toMatch( + /This is the my-lib root route.<\/div>} \/>/ + ); + }); + }); + describe('--buildable', () => { it('should default to rollup bundler', async () => { await libraryGenerator(tree, { diff --git a/packages/react/src/generators/library/library.ts b/packages/react/src/generators/library/library.ts index fd26ad9733..f0168729b9 100644 --- a/packages/react/src/generators/library/library.ts +++ b/packages/react/src/generators/library/library.ts @@ -248,6 +248,7 @@ export async function libraryGeneratorInternal(host: Tree, schema: Schema) { export: true, routing: options.routing, js: options.js, + name: options.name, inSourceTests: options.inSourceTests, skipFormat: true, globalCss: options.globalCss,