質問

How would I go about denying access to a partial views with node.js/express? I have various different views in my single page web app and would like some pages to not be shown unless a user is logged in. How would I go about doing so? I know this might be vague, but I would like to have a general idea before actually coding in anything.

EDIT:

for example,

since my page is a single page app everything should be pulled up on the main page when any certain button is clicked, and the URL be handled from my side. But, I have the issue that if I type in something like:

http://www.mypage.com/login

the elements load, but they come out wrong. I would like to block the views from showing up unless they are clicked from a button on the main page. How would I do so?

Your help is appreciated.

役に立ちましたか?

解決

You can do the basic routing logic and call a method for routes which you want to restrict.

 app.get('/partials/view1, routes.partials);
 app.get('/partials/voew1', restrict, routes.partials);

In the restrict method redirect the flow to a generic 'restricted' view.

Check this : https://github.com/visionmedia/express/tree/master/examples/route-separation

他のヒント

Partials were obsoleted in Express 3. It's usually better to use the latest version of software.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top