1
1
import { Meteor } from 'meteor/meteor' ;
2
+ import { _ } from 'meteor/underscore' ;
2
3
import Router from './router.js' ;
3
4
import Route from './route.js' ;
4
5
import Group from './group.js' ;
5
6
import Triggers from './triggers.js' ;
6
7
import BlazeRenderer from './renderer.js' ;
7
8
import helpersInit from './active.route.js' ;
9
+ import { requestAnimFrame } from './modules.js' ;
8
10
9
11
const FlowRouter = new Router ( ) ;
10
12
FlowRouter . Router = Router ;
@@ -14,6 +16,51 @@ FlowRouter.Route = Route;
14
16
Meteor . startup ( ( ) => {
15
17
if ( ! FlowRouter . _askedToWait && ! FlowRouter . _initialized ) {
16
18
FlowRouter . initialize ( ) ;
19
+
20
+ FlowRouter . route ( '/___refresh/:layout/:template/:oldRoute?' , {
21
+ name : '___refresh' ,
22
+ action ( params , queryParams ) {
23
+ this . render ( params . layout , params . template , ( ) => {
24
+ requestAnimFrame ( ( ) => {
25
+ if ( params . oldRoute ) {
26
+ try {
27
+ if ( history . length ) {
28
+ window . history . go ( - 1 ) ;
29
+ } else {
30
+ FlowRouter . go ( params . oldRoute , ( queryParams . oldParams ? JSON . parse ( queryParams . oldParams ) : { } ) ) ;
31
+ }
32
+ } catch ( e ) {
33
+ FlowRouter . go ( '/' ) ;
34
+ }
35
+ } else {
36
+ if ( history . length ) {
37
+ window . history . go ( - 1 ) ;
38
+ } else {
39
+ FlowRouter . go ( '/' ) ;
40
+ }
41
+ }
42
+ } ) ;
43
+ } ) ;
44
+ }
45
+ } ) ;
46
+
47
+ FlowRouter . refresh = ( layout , template ) => {
48
+ if ( ! layout || ! _ . isString ( layout ) ) {
49
+ throw new Meteor . Error ( 400 , '[FlowRouter.refresh(layout, template)] -> "layout" must be a String!' ) ;
50
+ }
51
+
52
+ if ( ! template || ! _ . isString ( template ) ) {
53
+ throw new Meteor . Error ( 400 , '[FlowRouter.refresh(layout, template)] -> "template" must be a String!' ) ;
54
+ }
55
+
56
+ FlowRouter . go ( '___refresh' , {
57
+ oldRoute : FlowRouter . _current . route . name ,
58
+ layout,
59
+ template
60
+ } , {
61
+ oldParams : JSON . stringify ( FlowRouter . _current . params || { } )
62
+ } ) ;
63
+ } ;
17
64
}
18
65
} ) ;
19
66
0 commit comments