0

I have created a SPA, and I'm using Angular to do this. Now I have encountered a problem when I need to read the urls "created" with Angular in Node.js.

For example:

My url is:

http://example.com/#/home?answer=yes

Normally if the url would have been like this:

http://example.com/home?answer=yes

I could've gotten the "answer" by using:

app.get("/home", function(req,res) {
 var answer = req.query.answer;
})

But because of the # node can't seem to parse the url.

Please help me solve this problem.

1 Answer 1

0

The part of the url after the # is called the fragment part, which is traditionally not even sent to the server, because it's meant to contain data for the client-side.

See wikipedia on the fragment identifier for details:

the agent sends the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent processes the resource according to the document type and fragment value

This means that when you send a GET request for such a URL as http://example.com/#/home?answer=yes in your example, example.com will be fetched for you, and it is up to your client-side code to parse the #/home?answer=yes fragment, which would by convention involve something like rendering the home route (within the SPA), considering the given value of the answer parameter.

For the reasons above, if you want to parse the /home?answer part on the server-side, your request URL should contain them before any # signs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.