我可以链接到.html页面的.ejs页面吗? [英] Can I link to a .ejs-page from a .html-page?

查看:192
本文介绍了我可以链接到.html页面的.ejs页面吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作网页,并且一直在关注如何从.html文件链接到.ejs文件的stackoverflow。



大家都在说下面的内容:



在index.html中:

 < li>< a href =/ twitter> Twitter< / a>< / li> 

在script.js中:

  app.get('/ twitter',function(req,res){
res.render('twitter',{});
});

但它不适用于我。它说你的文件没有找到。它适用于本地主机,但不是当我第一次点击index.html,然后从那里点击twitter.ejs页面。我的代码如下所示: jsfiddle



twitter.ejs位于视图文件夹中,而index位于此文件夹之外。



有什么不对?

解决方案

情况是你想直接链接到视图模板。



你需要创建一个路由到一个Twitter控制器,然后调用您的模板。它看起来像这样:

router.get('/ twitter',twitterController.twitter_view);


I am making a webpage and I have been looking on stackoverflow on how to link to .ejs-files from a .html-file.

People are saying the following

In index.html:

<li><a href="/twitter">Twitter</a></li>

In script.js:

app.get('/twitter',function(req,res){
 res.render('twitter', { });
});

But it does not work for me. It says "Your file was not found". It works on localhost, but not when I first click on index.html and then click on twitter.ejs page from there. My code looks like this: jsfiddle.

twitter.ejs is in a view folders, while index is outside of this folder.

What is wrong?

解决方案

The situation is you're trying to link directly to a view template.

You need to create a route to a twitter controller that then calls your template. It would look something like this:

router.get('/twitter', twitterController.twitter_view);

这篇关于我可以链接到.html页面的.ejs页面吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆