Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stark-core): add support for deep state navigation for states from lazy loaded modules. Adapt Showcase to make DemoModule and NewsModule lazy loaded #814

Conversation

christophercr
Copy link
Collaborator

@christophercr christophercr commented Oct 31, 2018

ISSUES CLOSED: #810

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[X] Feature
[ ] Code style update (formatting, local variables)
[X] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #810

What is the new behavior?

  • The logic to navigate to the Login/Preloading state is now in the StarkSessionModule in "stark-core" where it belongs.
  • The definition of the starkAppInitStateName and starkAppExitStateName is now in the StarkSessionModule in "stark-core" where it belongs.
  • The targetRoute resolve from the starkAppInitStateName now checks if the target state is part of a lazy module. In that case it lazy loads the module first and then search for the right target state.
  • Adapted some UI components to import the Angular CommonModule instead of the BrowserModule and BrowserAnimationsModule, since those modules should be loaded only once in the app.

Does this PR introduce a breaking change?

[ ] Yes
[X] No

Other information

Adapted the DemoModule and NewsModule in the Showcase to make them lazy loaded modules.

@coveralls
Copy link

coveralls commented Oct 31, 2018

Coverage Status

Coverage decreased (-0.04%) to 91.388% when pulling 6589846 on christophercr:feature/stark-session-lazy-loading-support into 94eb491 on NationalBankBelgium:master.

StarkLoginPageComponent,
StarkPreloadingPageComponent,
StarkSessionExpiredPageComponent,
StarkSessionLogoutPageComponent
],
exports: [StarkLoginPageComponent, StarkPreloadingPageComponent, StarkSessionExpiredPageComponent, StarkSessionLogoutPageComponent],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has Prettier been runned on this file ? Could you reformat this ? 😊

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in fact it was prettier the one that changed this line ;)

{
name: "home",
url: "",
views: { "@": { component: HomeComponent } },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why having the views: {"@": {}} here ?

Copy link
Collaborator Author

@christophercr christophercr Oct 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, because now that we implemented lazy loaded modules, the states graph was not correct and any navigation to lazy loaded modules failed.

So, I had to adapt the graph: basically I added the AppComponent as the root state of the app, so that means that the <ui-view> is no longer in the root Ui Router state but in a child route, therefore the views: { "@": { component: xxxxx } } is needed to render the page in that ui-view.

This is how the states graph looks now:
showcase router state graph

{
name: "demo.action-bar",
url: "/action-bar",
views: { "@": { component: DemoActionBarComponent } }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we simply declare our states as before like this:

{
  name: "demo.action-bar",
  url: "/action-bar",
  component: DemoActionBarComponent
},

? 😊

Copy link
Collaborator Author

@christophercr christophercr Oct 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nop, we need the views: { "@": { component: HomeComponent } } construct, see my previous comment.

export const NEWS_STATES: Ng2StateDeclaration[] = [
{
name: "news",
url: "^/news",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why declare url: "^/news" here and in demo module, declare url: "^/dropdown" ?

Copy link
Collaborator Author

@christophercr christophercr Oct 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?? I don't think we have url: "^/dropdown" in the demo module... we do have url: "/dropdown".

In any case, if you are wondering about the ^, that is used to avoid double slash "//" in the URL after the domain (https://github.com/angular-ui/ui-router/wiki/URL-Routing#absolute-routes-). Otherwise, when we navigate to a demo page we will have a URL with double slashes (http://localhost:3000///demo/somePage") 😕

@christophercr christophercr force-pushed the feature/stark-session-lazy-loading-support branch from 4f731e3 to c81fe00 Compare October 31, 2018 15:26
@SuperITMan
Copy link
Member

@christophercr could you please rebase your PR ? 😊

@christophercr christophercr force-pushed the feature/stark-session-lazy-loading-support branch from c81fe00 to e4885c1 Compare November 2, 2018 15:45
…om lazy loaded modules. Adapt Showcase to make DemoModule and NewsModule lazy loaded

ISSUES CLOSED: #810
@christophercr christophercr force-pushed the feature/stark-session-lazy-loading-support branch from e4885c1 to 6589846 Compare November 2, 2018 15:46
@christophercr
Copy link
Collaborator Author

Rebased 😉

@SuperITMan SuperITMan merged commit 2ba3d6e into NationalBankBelgium:master Nov 2, 2018
@christophercr christophercr deleted the feature/stark-session-lazy-loading-support branch November 6, 2018 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ui: session - Preloading page cannot redirect to a state that is part of a lazy loaded module
3 participants