question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use lazy loading for wildcard route

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Add a wildcard route for handling 404’s as described in documentation - https://angular.io/docs/ts/latest/guide/router.html. It works. Change the PageNotFoundComponent to be lazy loaded (exactly as any other lazy loaded component - which are working in same application) and instead of navigation you get an error on an unmatched route:

error_handler.js:47 EXCEPTION: Uncaught (in promise): TypeError: segment.hasChildren is not a function
TypeError: segment.hasChildren is not a function
    at serializeSegment (http://localhost:4200/main.bundle.js:8576:17)
    at serializeSegment (http://localhost:4200/main.bundle.js:8578:13)
    at DefaultUrlSerializer.serialize (http://localhost:4200/main.bundle.js:8565:29)
    at Router.serializeUrl (http://localhost:4200/main.bundle.js:14731:80)
    at MergeMapSubscriber.project (http://localhost:4200/main.bundle.js:14827:231)
    at MergeMapSubscriber._tryNext (http://localhost:4200/main.bundle.js:11011:27)
    at MergeMapSubscriber._next (http://localhost:4200/main.bundle.js:11001:18)
    at MergeMapSubscriber.Subscriber.next (http://localhost:4200/main.bundle.js:2737:18)
    at CatchSubscriber.Subscriber._next (http://localhost:4200/main.bundle.js:2773:26)
    at CatchSubscriber.Subscriber.next (http://localhost:4200/main.bundle.js:2737:18)

Making no changes other then changing the route path from ‘**’ to ‘foo’ and navigating to ‘foo’, the component lazy loads as expected, so it only the wildcard path that’s causing the issue.

Expected behavior

Page should navigate to the correct lazy loaded component.

Minimal reproduction of the problem with instructions

Simple to reproduce. See https://github.com/slubowsky/wildcard-lazy-load-issue. Didn’t even have to add a separate component. Just reused one lazy loaded component. On start up, the lazy loaded component shows as the default route. Click “Foo”. Instead of loading same exact lazy component for the wildcard route you get an error as described above.

What is the motivation / use case for changing the behavior?

Want to keep app as small as possible. Don’t expect any 404’s but want the component available to be lazy loaded just in case

Please tell us about your environment:

Windows 10, Visual Studio Code, Node 7.0.0, Angular-cli 1.0.0-beta.20-4 ng serve

  • Angular version: 2.0.X

2.2.1, router 3.2.1

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

Only tried in Chrome

  • Language: [all | TypeScript X.X | ES6/7 | ES5] Typescript 2.0.10

  • Node (for AoT issues): node --version =

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
slubowskycommented, Dec 16, 2016

@felipedrumond I didn’t. Doesn’t break anything for me to make it eagerly loaded for now, and will be simple for me to switch to lazy whenever this bug is fixed, just change component back to loadChildren and remove the import

0reactions
angular-automatic-lock-bot[bot]commented, Sep 10, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular lazy loading routing always goes to wildcard module
In the following (simplified) example, I want to lazy load the StoreModule . If no url is given, I want my application to...
Read more >
6. Angular 9 : Lazy loading :Wildcard Route - YouTube
In this complete video series, we are going to develop one TODO application and will cover all the topics for Angular 9, please...
Read more >
Working with Angular 14 Router - Techiediaries
We'll learn how to use multiple outlets, redirect users from the empty path, use wild-card paths to implement 404 error pages and lazy...
Read more >
How to Routing and Lazy loading in Angular - Referbruv
The “empty route” is placed before the “wildcard” but at the end of the Routes. The RoutingTable starts with generic routes such as...
Read more >
Relationship Loading Techniques — SQLAlchemy 1.3 ...
Lazy loading refers to objects are returned from a query without the related ... The above wildcard will apply to all relationships not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found