git.fiddlerwoaroof.com
Ed Langley authored on 18/06/2017 03:11:57
Showing 1 changed files
... ...
@@ -281,6 +281,7 @@ function constructPath(match) {
281 281
 
282 282
 function createActionDispatcher(routesConfig, window) {
283 283
   let {compiledActionMatchers, compiledRouteMatchers} = compileRoutes(routesConfig);
284
+  let current_location = null;
284 285
 
285 286
   let actionDispatcher = {
286 287
     store: null,
... ...
@@ -297,7 +298,6 @@ function createActionDispatcher(routesConfig, window) {
297 298
       }
298 299
     },
299 300
     handleEvent(ev) {
300
-
301 301
       if (!this.store) {
302 302
         throw new Error("You must call activateDispatcher with redux store as argument");
303 303
       }
... ...
@@ -307,7 +307,8 @@ function createActionDispatcher(routesConfig, window) {
307 307
     },
308 308
     receiveLocation(location) {
309 309
       const match = matchRoute(location, compiledRouteMatchers);
310
-      if(match) {
310
+      if(current_location !== location.pathname && match) {
311
+        current_location = location.pathname;
311 312
         const action = constructAction(match);
312 313
 
313 314
         this.store.dispatch(action);
... ...
@@ -333,7 +334,7 @@ function createActionDispatcher(routesConfig, window) {
333 334
 function buildMiddleware(actionDispatcher) {
334 335
   return store => next => action => {
335 336
     if (actionDispatcher.handlesAction(action)) {
336
-        actionDispatcher.receiveAction(action, store);
337
+      actionDispatcher.receiveAction(action, store);
337 338
     }
338 339
     return next(action);
339 340
   };
... ...
@@ -345,5 +346,9 @@ export default function installBrowserRouter(routesConfig, window) {
345 346
 
346 347
   const middleware = buildMiddleware(actionDispatcher);
347 348
 
348
-  return {middleware, enhancer: actionDispatcher.enhanceStore};
349
+  return {
350
+    middleware,
351
+    enhancer: actionDispatcher.enhanceStore,
352
+    init: actionDispatcher.receiveLocation.bind(actionDispatcher, window.location)
353
+  };
349 354
 }