Vulcan/packages/nova-base-routes/lib/routes.jsx
Comus Leong 464e20a96c eslint & clean up code, also fixed some bugs (#1515)
* [eslint] update eslint rules & add .eslintignore to ignore non-ready nova packages

* [clean-up] nova-voting

* [clean-up] [bug] nova-users: missing user parameter

* [clean-up] nova-users

* [clean-up] nova-subscribe

* [clean-up] nova-settings

* [clean-up] nova-rss

* [clean-up] [bug] nova-posts: correct UsersRemoveDeletePosts

* [clean-up] nova-posts

* [clean-up] nova-notifications

* [clean-up] [bug] nova-newsletter: no error.message on throw error

* [clean-up] nova-newsletter

* [clean-up] nova-lib

* [clean-up] nova-kadira

* [clean-up] nova-inject-data

* [clean-up] nova-getting-started

* [clean-up] nova-forms

* [clean-up] nova-events

* [clean-up] [bug] nova-embedly: no FlowRouter

* [clean-up] nova-embedly

* [clean-up] nova-email-templates

* [clean-up] nova-email

* [clean-up] nova-debug

* [clean-up] nova-core

* [clean-up] [bug] nova-comments: correct UsersRemoveDeleteComments

* [clean-up] nova-comments

* [clean-up] [bug] nova-cloudinary: use Telescope.settings.collection instand

* [clean-up] nova-cloudinary

* [clean-up] nova-categories

* [clean-up] nova-base-components

* [clean-up] nova-api

* [eslint] extends react recommended

* [clean-up] for jsx files

* [eslint] extends meteor recommended

* i forgot this one little change
2016-11-25 13:46:55 -05:00

69 lines
2.6 KiB
JavaScript

import Telescope from 'meteor/nova:lib';
import { Messages } from 'meteor/nova:core';
import Events from "meteor/nova:events";
import { ReactRouterSSR } from 'meteor/reactrouter:react-router-ssr';
import React from 'react';
import Helmet from 'react-helmet';
import Cookie from 'react-cookie';
import ReactDOM from 'react-dom';
// import {mount} from 'react-mounter';
// import { IndexRoute, Route, useRouterHistory, browserHistory, createMemoryHistory } from 'react-router';
// import { ListContainer, DocumentContainer } from "meteor/utilities:react-list-container";
// import useNamedRoutes from 'use-named-routes';
// import createBrowserHistory from 'history/lib/createBrowserHistory';
Telescope.routes.indexRoute = { name: "posts.list", component: Telescope.components.PostsHome };
Meteor.startup(() => {
Telescope.routes.add([
{name:"posts.daily", path:"daily", component:Telescope.components.PostsDaily},
{name:"posts.single", path:"posts/:_id(/:slug)", component:Telescope.components.PostsSingle},
{name:"users.single", path:"users/:slug", component:Telescope.components.UsersSingle},
{name:"users.account", path:"account", component:Telescope.components.UsersAccount},
{name:"resetPassword", path:"reset-password/:token", component:Telescope.components.UsersResetPassword},
{name:"users.edit", path:"users/:slug/edit", component:Telescope.components.UsersAccount},
{name:"app.notfound", path:"*", component:Telescope.components.Error404},
]);
const AppRoutes = {
path: '/',
component: Telescope.components.App,
indexRoute: Telescope.routes.indexRoute,
childRoutes: Telescope.routes.routes
}
// let history;
const clientOptions = {
renderHook: ReactDOM.render,
props: {
onUpdate: () => {
Events.analyticsRequest();
Messages.clearSeen();
}
}
};
const serverOptions = {
htmlHook: (html) => {
const head = Helmet.rewind();
return html.replace('<head>', '<head>'+ head.title + head.meta + head.link);
},
preRender: (req, res) => {
Cookie.plugToRequest(req, res);
},
};
ReactRouterSSR.Run(AppRoutes, clientOptions, serverOptions);
// note: we did like this at first
// if (Meteor.isClient) {
// history = useNamedRoutes(useRouterHistory(createBrowserHistory))({ routes: AppRoutes });
// }
// if (Meteor.isServer) {
// history = useNamedRoutes(useRouterHistory(createMemoryHistory))({ routes: AppRoutes });
// }
// ReactRouterSSR.Run(AppRoutes, {historyHook: () => history}, {historyHook: () => history});
});