ssrwpo / ssr

SSR - Router with SSR for Node & Meteor
https://ssrwpo.github.io/ssr/
MIT License
93 stars 16 forks source link

location.search on server #57

Closed s7dhansh closed 7 years ago

s7dhansh commented 7 years ago

How to get the query parameters from the url on the server? The props.location.search parameter is always blank on server.

cbilotta commented 7 years ago

Hello,

Can you give a code example ?

s7dhansh commented 7 years ago

In the demo itself (both master and develop branches), I replaced the

const NotFound = ({ location }, { router }) => {
  if (Meteor.isServer) {

with

const NotFound = ({ location }, { router }) => {
  console.log(1, location);
  if (Meteor.isServer) {

in the imports/routes/NotFound.jsx file.

Now when I go to http://localhost:3000/anything?abc=1, it prints

1 { pathname: '/login1', search: '', hash: '' }

on the server, but

1 Object {pathname: "/login1", search: "?abc=1", hash: "", state: undefined, key: undefined}

on the client.

cbilotta commented 7 years ago

Ha okay.

It's normal. You need to whitelist url parameters server side.

See this file : https://github.com/ssrwpo/ssr/blob/master/demo/server/urlQueryParameters.js

s7dhansh commented 7 years ago

Oh great! My bad for not checking the demo out properly. The format is a bit changed in the develop branch, but it works.

cbilotta commented 7 years ago

Cool! Have a great day :)