简体   繁体   English

如何将文件夹中的页面设置为 URL localhost:端口号?

[英]How to set a page within a folder to the URL localhost: port-number?

I currently access my login page typing in the following URL to my browser - ' http://localhost:3000/pages/login '.我目前访问我的登录页面,在我的浏览器中输入以下 URL - ' http://localhost:3000/pages/login '。 The login page file is within a folder called 'pages'.登录页面文件位于名为“pages”的文件夹中。 I want to be able to be directed to the login page when I enter the following URL - ' http://localhost:3000/ '.当我输入以下 URL - ' http://localhost:3000/ ' 时,我希望能够被定向到登录页面。 I know this might be incredibly easy to some of you, but I am very new to this and I have became confused with the application I using.我知道这对你们中的一些人来说可能非常容易,但我对此很陌生,我对我使用的应用程序感到困惑。

Here is my code below这是我下面的代码

controller file controller 文件

//renders the login.hbs page
router.get('/login', (req, res) => {
    res.render('pages/login', {
        layout: 'main.hbs'
    });
});

I tried changing the following code in numerous ways but it ended up giving me an error in which the page could not be found or trying to locate pages/pages/login.我尝试以多种方式更改以下代码,但最终给我一个错误,即找不到页面或试图找到页面/页面/登录。 I am guessing if its in a folder 'pages' then this cant be done?我猜如果它在文件夹“页面”中,那么这不能完成吗?

remove the route from pages router and add it to the app.js or your main server file directly like below.从页面路由器中删除路由并将其添加到 app.js 或您的主服务器文件中,如下所示。

make sure to remove any other routes that are attached to / route and also delete the index.html file from public folder.确保删除附加到/ route 的任何其他路由,并从公共文件夹中删除 index.html 文件。

app.get('/', (req, res) => {
    res.render('pages/login', {
        layout: 'main.hbs'
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM