Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Node.JS I can't go to another ejs page.

dt65231

Coder
I can't go to another ejs page.

Index.ejs
HTML:
<h1>Index page</h1>

<a href="/about" >About-1. Описание</a> </br>
<a href="http://localhost:3000/About/" >About-2. Описание</a>



In routes.js added.
JavaScript:
.get('/about', (req, res) => {
       res.render('about');
      })



routes.js Full code

JavaScript:
const multer = require('multer');
const rand = require('randomstring');

const filesStorage = multer.diskStorage({
  destination: (req, file, next) => {
    next(null, 'static/uploads/files');
  },
  filename: (req, file, next) => {
    const ext = file.originalname.split('.').pop();
    next(null, rand.generate({
      length: 32,
      charset: 'alphabetic'
    }) + '.' + ext);
  }
});
const filesUpload = new multer({
  storage: filesStorage
});


const site = {
  main: require('./controllers/main')
};

const cms = {
  articles: require('./controllers/cms/articles'),
  files: require('./controllers/cms/files'),
  lang: require('./controllers/cms/lang'),
  slideshow: require('./controllers/cms/slideshow')
};

module.exports = (app, passport) => {

  app
    .get('/', site.main.lang)
    .get('/video', site.main.video)
    .get('/slideshow', site.main.slideshow)
    .get('/:lang', site.main.index)
    
    /*articles*/       
    .get('/:lang/articles', site.main.index)
    .get('/:lang/articles/:id', site.main.article)

    .get('/:lang/panomuseum', site.main.panomuseum)
    .get('/:lang/panomuseum/2', site.main.panomuseum2)
    .get('/:lang/panotheatre', site.main.panotheatre)
    
    /*My*/
    // .get('/:lang/articles', site.main.index)
    .get('/Index', site.main.index)
     .get('/history', site.main.history)
    // .get('/history', (req, res) => {
    //   res.render('history');
    //  })
     .get('/about', (req, res) => {
       res.render('about');
      })
    ;


  app

    .get('/cms/lang', cms.lang.index)
    .post('/cms/lang', filesUpload.any(), cms.lang.save)

    .get('/cms/:lang/articles', cms.articles.index)
    .post('/cms/articles/saveOrder', cms.articles.saveOrder)

    .get('/cms/:lang/articles/add', cms.articles.add)
    .post('/cms/:lang/articles/add', filesUpload.any(), cms.articles.postAdd)

    .get('/cms/:lang/articles/:id/edit', cms.articles.edit)
    .post('/cms/:lang/articles/:id/edit', filesUpload.any(), cms.articles.postEdit)
    .get('/cms/:lang/articles/:id/delete', cms.articles.delete)

    .get('/cms/:lang/articles/:id', cms.articles.subArticle)
    .get('/cms/:lang/articles/add/:id', cms.articles.add)

    .post('/cms/files/delete', cms.files.delete)
    .post('/cms/files/saveFile', filesUpload.single('file'), cms.files.saveFile)
    .post('/cms/files/saveThumb', filesUpload.single('thumb'), cms.files.saveThumb)

    .get('/cms/slideshow', cms.slideshow.index)
    .post('/cms/slideshow/save', filesUpload.any(), cms.slideshow.save);

  return app;


11.08.2022_00-58-29.png

11.08.2022_01-02-16.png
 
Talking about <a href="/about" >About-1. Описание</a> </br>
'First, where is the page? Let's assume it's in the same folder as the page with this anchor.
Remove the /. This is relative shorthand for the root and not the folder you are in.
Next, every page needs a suffix. For most websites, it's .html.
So the call is <a href="about.html" >About-1. Описание</a> </br>

The next link uses localhost. Which is on your computer, not on a server. This should be the same as the first link:
<a href="about.html" >About-2. Описание</a> Or whatever you named this page.
 

New Threads

Buy us a coffee!

Back
Top Bottom