-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathrouter.js
128 lines (105 loc) · 3.8 KB
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import EmberRouter from '@ember/routing/router';
import { scheduleOnce } from '@ember/runloop';
import config from 'ember-api-docs/config/environment';
import { inject as service } from '@ember/service';
class AppRouter extends EmberRouter {
location = config.locationType;
rootURL = config.routerRootURL;
@service metrics;
@service fastboot;
constructor() {
super(...arguments);
if (!this.fastboot.isFastBoot) {
this.on('routeDidChange', this, this._trackPage);
}
}
_trackPage() {
scheduleOnce('afterRender', this, this.__trackPage);
}
__trackPage() {
// this is constant for this app and is only used to identify page views in the GA dashboard
const hostname = config.APP.domain.replace(/(http|https)?:?\/\//g, '');
const page = this.url;
const title =
this.currentRouteName === undefined ? 'unknown' : this.currentRouteName;
this.metrics.trackPage({ page, title, hostname });
}
}
AppRouter.map(function () {
this.route('project', { path: '/:project' });
this.route(
'project-version',
{ path: '/:project/:project_version' },
function () {
// this.route('classes-redirect', {path: '/classes'});
// project-version.classes-redirect => project-version.classes.index
// project-version.class => project-version.classes.class
this.route('classes', function () {
this.route('class', { path: '/:class' }, itemRoutes);
});
// this.route('class', {path: '/classes/:class'}, itemRoutes);
this.route('functions', function () {
this.route('function', { path: '/:module/:fn' });
});
// Namespace routes
// project-version.namespace => project-version.namespaces.namespace
// routes/project-version/namespace => routes/project-version/namespaces/namespace
this.route('namespaces', function () {
this.route('namespace', { path: '/:namespace' }, itemRoutes);
});
// this.route('namespace', {path: '/namespaces/:namespace'}, itemRoutes);
// Module routes
// project-version.module => project-version.modules.module
// routes/project-version/module => routes/project-version/modules/module
// routes/project-version/module/* => routes/project-version/modules/module/*
this.route('modules', function () {
this.route('module', { path: '/:module' }, itemRoutes);
});
// this.route('module', {path: '/modules/:module'}, itemRoutes);
// Common sub-routes
function itemRoutes() {
this.route('methods', function () {
this.route('method', { path: '/:method' });
});
this.route('properties', function () {
this.route('property', { path: '/:property' });
});
this.route('events', function () {
this.route('event', { path: '/:event' });
});
}
}
);
this.route('class', { path: '/classes/:class' });
this.route('module', { path: '/modules/:module' });
this.route('data-class', { path: '/data/classes/:class' });
this.route('data-module', { path: '/data/modules/:module' });
});
/*
404
ember-cli
project
/:project/:project_version
/classes/:class
/methods, /properties, /events
/functions/:module (no sub routes)
/namespaces/:namespace
/methods, /properties, /events
/modules/:module
/methods, /properties, /events
SUB ROUTES
Instead of https://api.emberjs.com/ember/4.6/classes/Engine/methods/unregister?anchor=unregister
We can do https://api.emberjs.com/ember/4.6/classes/Engine/methods?anchor=unregister
/methods/:method
/properties/:property
/events/:event
OTHER STATES
private, deprecated, inherited, protected
inherited is not reflected in URL state but it's checked by default
MAYBE REDIRECTS
/data/modules/:module
/data/classes/:class
/modules/:module
/classes/:class
*/
export default AppRouter;