将Express默认路由重定向到新路由

将Express默认路由重定向到新路由,express,handlebars.js,feathersjs,express-handlebars,Express,Handlebars.js,Feathersjs,Express Handlebars,我有FeathersJS应用程序(位于Express的顶部),我使用车把作为模板引擎 我想将express的“/”重定向到其他URL,但它一直在/public文件夹中加载index.html。我的目标是将它重定向到一个车把页面,这样我就可以使用布局,而不会重复我自己 const path = require('path'); const favicon = require('serve-favicon'); const compress = require('compression'); con

我有FeathersJS应用程序(位于Express的顶部),我使用车把作为模板引擎

我想将express的“/”重定向到其他URL,但它一直在/public文件夹中加载index.html。我的目标是将它重定向到一个车把页面,这样我就可以使用布局,而不会重复我自己

const path = require('path');
const favicon = require('serve-favicon');
const compress = require('compression');
const cors = require('cors');
const helmet = require('helmet');
const logger = require('winston');

const feathers = require('@feathersjs/feathers');
const configuration = require('@feathersjs/configuration');
const express = require('@feathersjs/express');
const exphbs = require('express-handlebars');
const socketio = require('@feathersjs/socketio');


const middleware = require('./middleware');
const services = require('./services');
const appHooks = require('./app.hooks');
const channels = require('./channels');

const app = express(feathers());

app.set('views', path.join(app.get('views')));
app.engine('.hbs', exphbs({
    extname: '.hbs',
    defaultLayout: 'main'
}));
app.set('view engine', '.hbs');

// Load app configuration
app.configure(configuration());
// Enable CORS, security, compression, favicon and body parsing
app.use(cors());
app.use(helmet());
app.use(compress());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(favicon(path.join(app.get('public'), 'favicon.ico')));
app.use(express.static(app.get('public')));
// Host the public folder

app.get('/', function(req, res){
    console.log('test');
    res.redirect('/home');
});

app.get('/home', function(req, res, next){
    res.render('home');
});
app.get('/test', function(req, res, next){
    res.redirect('/');
});
app.get('/admin', function(req, res, next) {
    res.render('admin',{});
});
app.get('/services', function(req, res, next) {
    res.render('services',{});
});


// Set up Plugins and providers
app.configure(express.rest());
app.configure(socketio());

// Configure other middleware (see `middleware/index.js`)
app.configure(middleware);
// Set up our services (see `services/index.js`)
app.configure(services);
// Set up event channels (see channels.js)
app.configure(channels);

// Configure a middleware for 404s and the error handler
app.use(express.notFound());
app.use(express.errorHandler({ logger }));

app.hooks(appHooks);

module.exports = app;
我说的不是去“家”。我是不是错过了什么


谢谢大家!

这是因为您在
/
处理程序之前使用的是
express.static
中间件,因为在公用文件夹中有一个
index.html
,当您点击
/
时,它默认为索引文件,您可以这样切换顺序:

app.use(express.urlencoded({ extended: true }));
app.use(favicon(path.join(app.get('public'), 'favicon.ico')));

app.get('/', function(req, res){
console.log('test');
res.redirect('/home');
});

app.use(express.static(app.get('public')));
// Host the public folder

app.get('/home', function(req, res, next){
res.render('home');
});
app.get('/test', function(req, res, next){
res.redirect('/');
});

你能把整个文件拿出来吗?@HamzaFatmi我更新了我的问题。。在app.get(“/”,fn)