Reaction: Route Hooks did not work.

Created on 4 Sep 2017  路  6Comments  路  Source: reactioncommerce/reaction

Expected behavior

With route hook registered like this:

Router.Hooks.onEnter("index", function () {
   console.log("=Test onEnter hook=");
});

The log should be outputted in the browser console.
before routing to main page,

Actual Behavior

There is no log outputted .

Steps to Reproduce the Behavior

Just go to the main page.

Versions

Release 1.4.0

In js file:

reaction/imports/plugins/core/router/client/browserRouter.js

handleLocationChange() function

line 105:   Router.Hooks.run("onExit", previousRoute.name, previousRoute);

line 112:  Router.Hooks.run("onEnter", routeData.name, routeData);

I think previousRoute.name should be changed to previousRoute.route.name and routeData.name should be changed to routeData.route.name.

Because the router state object, the object returned by Router.current(), does not have "name" property, only route object has.

bug

All 6 comments

@jshimko this could use your eyes.. I think you wrote this originally? I'm not sure if it was updated in the new react-router rewrite?

Also, need tests on this, should be failing if they don't work...

Related to #2760, which is a more general scoped marketplace router task.

This was updated for the react router re-write, but React Router has no concept of "onEnter" / "onLeave" for routes. An attempt was made to replicate this functionality in browserrouter.js of the router package here: https://github.com/reactioncommerce/reaction/blob/marketplace/imports/plugins/core/router/client/browserRouter.js#L106

More eyes would help.

@jshimko this is assigned to you. If you aren't going to review, or add comments, I'm removing your assignment.

Resolved in #3043

Was this page helpful?
0 / 5 - 0 ratings