I come from a PHP background and I'm new to Node JS development. I decided to try a basic Meteor JS + Iron Router + React project. The following behaviour caught me off guard:
I'm on a page like
http://192.168.0.110:3000/dashboard/johnand it has a link like<a href="/dashboard/john/111222">. When the page first loads, a client side javascript variablemyvariablehas the valueundefinedbut I set it tomyvariable="hello world"as the page loads.When I click on the
<a href="/dashboard/john/111222">link, the page loads up, but to my surprise, themyvariablealready has the valuehello worldinstead ofundefined.
So even though I went to a totally new url, in which I expected a full page refresh, the myvariable maintained the value of the previous page. Because of my PHP background, I was expecting the value undefined.
This is a completely new behaviour to me because if this were a PHP project, I would have had to explicitly write code to give the illusion that client side javascript variables persist across different page urls (or I use ajax to redraw the screen). But with my NodeJS project, I didn't have to do any of that, and the client side variable maintained it's value.
So my question is, what is this behaviour called? And is it Node JS, Meteor, Iron Router or React that's responsible for this behaviour? Once I know the name of this behaviour, then I can google and read up on details.
Here's the code for my project:
myproject.jsx
var myvariable;
var configAppRoute = {action:applicationController};
Router.route('/dashboard/:username',configAppRoute);
Router.route('/dashboard/:username/:appid',configAppRoute);
function applicationController()
{
console.log(myvariable);
myvariable='hello world';
console.log(myvariable);
Meteor.startup(function () {
ReactDOM.render(<App />, document.getElementById("render-target"));
});
}
App.jsx
App = React.createClass({
render() {
return (
<div>
<a href={'/dashboard/john/111222'}>click me</a>
</div>
);
}
});
myproject.html
<head>
<title>My Project</title>
</head>
<body>
<div id="render-target"></div>
</body>
Data on the Wire. Meteor doesn't send HTML over the network. The server sends data and lets the client render it-- which means that meteor based app are single page apps. I haven't used meteor so I'm not 100% sure but meteor probably rewrites your link to do an ajax call and render it in the same page. That would explain the behavior you're seeing. FWIW you can do this in PHP as well. Facebook is an example of an app written in PHP that behaves like this.