在 BrowserSync 中,如何匹配特定的路由并重定向?
In BrowserSync, how can you match an specific route and redirect?
在 BrowserSync 中,如何匹配特定的路由并重定向?
换句话说,如果用户输入
的路径
http://localhost:8080/src/public/App1/Dashboard
我想重定向到:
http://localhost:8080/src/public/index.html#/App1/Dashboard
这是我当前的配置
gulp.task('x_open_server_development_auto', ['x_watch_source'], function () {
process.stdout.write('Starting browserSync and superstatic...\n');
browserSync({
port: 8080,
open: false,
files: ['index.html', '**/*.ts'],
notify: true,
reloadDebounce: 400,
server: {
baseDir: './',
directory: true
}
});
// exit every 20 minutes so forever will restart it
setTimeout(function () {
process.exit()
}, 3200000);
});
发送肖恩
browser-sync
允许您定义可用于处理请求的 middleware:
browserSync({
port: 8080,
open: false,
files: ['index.html', '**/*.ts'],
notify: true,
reloadDebounce: 400,
server: {
baseDir: './',
directory: true
},
middleware: [
function(req, res, next) {
if (/\/src\/public\/App1\/Dashboard\/?/.test(req.url)) {
res.writeHead(302, {
'Location': '/src/public/index.html#/App1/Dashboard'
});
res.end();
}
next();
}
],
});
在 BrowserSync 中,如何匹配特定的路由并重定向? 换句话说,如果用户输入
的路径http://localhost:8080/src/public/App1/Dashboard 我想重定向到: http://localhost:8080/src/public/index.html#/App1/Dashboard
这是我当前的配置
gulp.task('x_open_server_development_auto', ['x_watch_source'], function () {
process.stdout.write('Starting browserSync and superstatic...\n');
browserSync({
port: 8080,
open: false,
files: ['index.html', '**/*.ts'],
notify: true,
reloadDebounce: 400,
server: {
baseDir: './',
directory: true
}
});
// exit every 20 minutes so forever will restart it
setTimeout(function () {
process.exit()
}, 3200000);
});
发送肖恩
browser-sync
允许您定义可用于处理请求的 middleware:
browserSync({
port: 8080,
open: false,
files: ['index.html', '**/*.ts'],
notify: true,
reloadDebounce: 400,
server: {
baseDir: './',
directory: true
},
middleware: [
function(req, res, next) {
if (/\/src\/public\/App1\/Dashboard\/?/.test(req.url)) {
res.writeHead(302, {
'Location': '/src/public/index.html#/App1/Dashboard'
});
res.end();
}
next();
}
],
});