This is going to be a little long, please forgive me. I’m still a bit of a noob and sometimes things don’t seem to click.
I’ve been trying to get SSR working for a while now with no success. I’ve tried to follow some online tuts and the meteor SSR documentation, however, I’m not really following what’s happening and as a result, I keep getting lost.
I’d like to be able to render public routes using SSR and have others not worry about it.
Instead of putting up one of my previous failed attempts I’ve put up my working app that doesn’t have SSR, with the hope that someone would be kind enough to show me what I’m supposed to do here.
Project
Meteor, React, Helmet
Path: client/main.html
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, shrink-to-fit=no">
</head>
<body>
<div id="react-target"></div>
</body>
Path: imports/ui/layouts/App.jsx
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import React from 'react';
import { Helmet } from 'react-helmet';
import PropTypes from 'prop-types';
import { withTracker } from 'meteor/react-meteor-data';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
const Index = () => <h1>Home page. index test.</h1>;
const Loading = () => <p>Loading...</p>;
const App = props => {
const { loading } = props;
if (loading) {
return (
<Router>
<div className="application">
<Helmet>
<meta charSet="utf-8" />
<title>My App</title>
<link rel="canonical" href="https://myapp.com" />
</Helmet>
<Navbar />
<Switch>
{/* Public routes - Load these with SSR for google */}
<Route path="/" exact component={Index} />
{/* Admin route */}
<Route path="/admin/users/create" exact component={CreateUsers} {...props} />
</Switch>
</div>
</Router>
);
}
return <Loading />;
};
const AppContainer = withTracker(() => {
const loading = Accounts.loginServicesConfigured();
return {
loading
};
})(App);
export default AppContainer;