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

Updates the navigation strategy to handle and expect a resolved strin… #393

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,21 @@ function validateRouteConfig(config: RouteConfig, routes: Array<Object>): void {
}

function evaluateNavigationStrategy(instruction: NavigationInstruction, evaluator: Function, context: any): Promise<NavigationInstruction> {
return Promise.resolve(evaluator.call(context, instruction)).then(() => {
return Promise.resolve(evaluator.call(context, instruction)).then((modules?: string | {[viewportname: string]: moduleId}) => {
if (!('viewPorts' in instruction.config)) {
instruction.config.viewPorts = {
'default': {
moduleId: instruction.config.moduleId
}
};
instruction.config.viewPorts = {};
}

if (typeof modules === 'string') {
modules = {'default': modules};
} else if (modules === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

For example, if someone has logic in their nav strat that falls back to a null value, they might expect it to run with the default config, but instead, modules will remain null and this will throw an unhandled error.

I'd recommend updating this to check for a falsey value.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Roustalski Can you update to handle this case?

modules = {'default': instruction.config.moduleId};
}

for (let key in modules) {
let vp = instruction.config.viewPorts[key] || {};
vp.moduleId = modules[key];
instruction.config.viewPorts[key] = vp;
}

return instruction;
Expand Down