Skip to content

Commit

Permalink
Fix nullability check in course and vote routes
Browse files Browse the repository at this point in the history
This commit fixes a nullability check in the CourseRoute and VoteRoute classes. The transition.to property is now properly checked for null
before accessing its name property. This change ensures that the code does not throw an error when transition.to is null, preventing
potential bugs.
  • Loading branch information
rohitpaulk committed Aug 14, 2024
1 parent 737f043 commit e474dac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/routes/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default class CourseRoute extends BaseRoute {
}

redirect(_model: ModelType, transition: Transition) {
if (transition.to.name === 'course.index') {
if (transition.to?.name === 'course.index') {
const activeStep = this.coursePageState.stepListAsStepList.activeStep;

// @ts-ignore not sure if we need to handle nullity here
Expand Down
2 changes: 1 addition & 1 deletion app/routes/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class VoteRoute extends BaseRoute {
}

afterModel(_model: ModelType, transition: Transition) {
if (transition.to.name === 'vote.index') {
if (transition.to?.name === 'vote.index') {
this.router.transitionTo('vote.course-ideas');
}
}
Expand Down
10 changes: 5 additions & 5 deletions app/utils/base-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export default class BaseRoute extends Route {
}

if (!this.allowsAnonymousAccess && !this.authenticator.isAuthenticated) {
const params = paramsFromRouteInfo(transition.to);
const params = transition.to ? paramsFromRouteInfo(transition.to) : [];

if (params.length > 0) {
const paramValues = params.map(([_, value]) => value);
this.authenticator.initiateLogin(this.router.urlFor(transition.to.name, ...paramValues));
this.authenticator.initiateLogin(this.router.urlFor(transition.to?.name || 'catalog', ...paramValues));
} else {
this.authenticator.initiateLogin(this.router.urlFor(transition.to.name));
this.authenticator.initiateLogin(this.router.urlFor(transition.to?.name || 'catalog'));
}

transition.abort();
Expand All @@ -44,9 +44,9 @@ export default class BaseRoute extends Route {
}
}

const queryParams = transition.to.queryParams;
const queryParams = transition.to?.queryParams;

if (queryParams['r'] && /^\d[a-zA-Z][a-zA-Z]$/.test(queryParams['r'])) {
if (queryParams && queryParams['r'] && /^\d[a-zA-Z][a-zA-Z]$/.test(queryParams['r'])) {
// @ts-ignore
this.utmCampaignIdTracker.setCampaignId(queryParams['r']);
delete queryParams['r'];
Expand Down

0 comments on commit e474dac

Please sign in to comment.