Comments (7)
On a separate but somewhat related note I am having issues with the render as well - I am trying to create a protected route following something like this http://www.aaron-powell.com/posts/2015-06-08-implementing-security-in-react-with-react-router.html
But my willTransitionTo
method is failing with the following error Error: Unhandled aborted transition! Reason: [object Object]
I have found a package that will solve this error https://github.com/ericclemmons/react-router-server-location but it will mean using a more decoupled router like the one above. I can create a separate issue for this is you like?
A simple example can be found here:
https://github.com/ericclemmons/react-router-server-location/blob/master/test/support/express.js
Fixing this would also help close #47
I can also create a test repo showing the issue as well.
from reactgo.
@kkotwal94 the boilerplate was meant to deal with nested routes initially, but I'm not sure it applies in your case. I'll have a look after I finish the protected routes feature #47 and get back to you on that :)
from reactgo.
Sure I'm going to continue to debug and figure it out, and thanks.
from reactgo.
app.get('*', function (req, res) {
Router.run(routes, req.path, function (Handler, state) {
var element = React.createElement(Handler);
var html = React.renderToString(element);
res.render('main', { content: html });
});
});
I tried to run this on the server, but I always thought UniversalRender took care of this so I'm a bit perplexed. If I try to run it on the server it yells at me that "import" is a reserved word. Then I tried to install babel and call require("babel/register");
but that didn't really work out either.
export default function UniversalRenderer(alt, routes, html) {
let render;
// if it is not a browser
if (typeof window === 'undefined') {
// if there is a html string passed in
// render the markup and inject it into the html string
if (html) {
render = (state, url) => {
const markup = renderToMarkup(alt, routes, state, url);
return html.replace('CONTENT', markup);
};
} else {
render = (state, url) => {
return renderToMarkup(alt, routes, state, url);
};
}
} else {
render = Iso.bootstrap((state, _, container) => {
alt.bootstrap(state);
Router.run(routes, Router.HistoryLocation, (Handler) => {
let node = React.createElement(Handler);
React.render(node, container);
});
});
}
return render;
}
Looking at the last else statement we are using history to grab the path anyways, so it should work O_O
from reactgo.
What happens is that webpack and babel compile the code into a function
which is used in routes.js in the server.
Nested routes shoudl work though. I'm currently working on a PR to use
react router 1.0 beta 3 so hopefully most of the issues will be resolved.
Still stuck with fixing it now :)
On Fri, 14 Aug 2015 04:08 Karan Kotwal [email protected] wrote:
app.get('*', function (req, res) {
Router.run(routes, req.path, function (Handler, state) { var element = React.createElement(Handler); var html = React.renderToString(element); res.render('main', { content: html }); });
});
I tried to run this on the server, but I always thought UniversalRender
took care of this so I'm a bit perplexed. If I try to run it on the server
it yells at me that "import" is a reserved word. Then I tried to install
babel and call require("babel/register"); but that didn't really work out
either.export default function UniversalRenderer(alt, routes, html) {
let render;
// if it is not a browser
if (typeof window === 'undefined') {
// if there is a html string passed in
// render the markup and inject it into the html string
if (html) {
render = (state, url) => {
const markup = renderToMarkup(alt, routes, state, url);
return html.replace('CONTENT', markup);
};
} else {
render = (state, url) => {
return renderToMarkup(alt, routes, state, url);
};
}
} else {
render = Iso.bootstrap((state, _, container) => {
alt.bootstrap(state);
Router.run(routes, Router.HistoryLocation, (Handler) => {
let node = React.createElement(Handler);
React.render(node, container);
});
});
}return render;
}Looking at the last else statement we are using history to grab the path
anyways, so it should work O_O—
Reply to this email directly or view it on GitHub
#50 (comment)
.
from reactgo.
@kkotwal94 Since the protected_routes change, has this still be an issue? I will close it if it has been resolved :)
from reactgo.
You can close!
On Tue, Sep 1, 2015 at 4:16 AM, Ken Ding [email protected] wrote:
@kkotwal94 https://github.com/kkotwal94 Since the protected_routes
change, has this still be an issue? I will close it if it has been resolved
:)—
Reply to this email directly or view it on GitHub
#50 (comment)
.
from reactgo.
Related Issues (20)
- webpack config file preload all different environment configs.
- Failed to serialize user into session when using MYSQL with Node and Passport. URGENT
- Easy deployment question HOT 4
- Postgres DB on port other than 5432 HOT 2
- New release / update changelog and publish to npm
- Remove usage of css @apply HOT 2
- Consider bundle size limits for vendor packages
- Close / Update old / rotten PRs
- Update all npm packages HOT 2
- Please re-install nodemon HOT 1
- Use hooks HOT 2
- Consider using easy-peasy on top of Redux HOT 1
- Do not bundle server application (Using Node.JS v. 9 with modules support) HOT 1
- [QUESTION] Where I can find the CI service? HOT 2
- Signup error when using CORS HOT 2
- Introducing immer
- Introducting TypeScript
- postcss-cssnext deprecated HOT 1
- Use react-router v5
- leadme 한글 공식문서 링크
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactgo.