3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 import React from 'react';
20 Router, Route, hashHistory, IndexRoute
23 import SkyquakeContainer from 'widgets/skyquake_container/skyquakeContainer.jsx';
25 export default function(config, context) {
28 let components = null;
29 if (config && config.routes) {
30 routes = buildRoutes(config.routes)
31 function buildRoutes(routes) {
32 return routes.map(function(route, index) {
34 if (route.route && route.component) {
35 // ES6 modules need to specify default
36 let path = route.route;
37 if(route.path && route.path.replace(' ', '') != '') {
43 getComponent: function(location, cb) {
44 require.ensure([], (require) => {
45 cb(null, context(route.component).default)
49 if(route.routes && (route.routes.length > 0)){
50 routeConfig.childRoutes = buildRoutes(route.routes)
53 console.error('Route not properly configured. Check that both path and component are specified');
61 component: require('../login/login.jsx').default
66 getComponent: function(loc, cb) {
67 cb(null, context(config.dashboard).default);
70 if (config.dashboard) {
71 // ES6 modules need to specify default
72 index = <IndexRoute component={context(config.dashboard).default} />;
74 index = DefaultDashboard
78 component: SkyquakeContainer,
82 component: (config.dashboard) ? context(config.dashboard).default : DefaultDashboard
88 <Router history={hashHistory} routes={rootRoute}>
92 console.error('There are no routes configured in the config.json file');
96 //When no default dashboard is specified in the plugin_config.json, use this component.
97 class DefaultDashboard extends React.Component {
103 html = <div> This is a default dashboard page component </div>;