繁体   English   中英

Node JS Express如果重定向到索引,则不会加载Webpack bundle js

[英]Node js express not loading webpack bundle js if redirected to index

我正在使用应用程序ID护照解决方案向网站添加登录功能。 护照位工作正常。

但是问题是当我重定向到链接我的捆绑软件的文件index.html时,它不会仅显示html捆绑软件。 为了清楚起见,它将找到index.html文件并加载html,但不加载索引文件中的包。 但是,如果我的index.html是通过express自动加载为索引文件的,则我的捆绑软件将显示出来。

因此,如果我转到基本网址页面,则该捆绑软件将显示,但是如果我进入/ login,然后将我的网站重定向到/public/index.html该捆绑软件将不会显示。

这个

app.get('/*',function(req,res,next){
     console.log("is user; ")
     console.log(req.user)
     if (req.user) {
         res.sendFile(__dirname + '/public/index.html'); 
     } else {
         res.redirect("/login")
      }
})

const LANDING_PAGE ="/public/index.html";
app.get("/login", passport.authenticate(WebAppStrategy.STRATEGY_NAME, {successRedirect : LANDING_PAGE, forceLogin: true}));

这不会显示捆绑包,但是使用

app.use(express.static(__dirname + '/public')); 

自动加载index.html并显示捆绑代码。

我的index.html文件

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo react</title>
    <link rel="shortcut icon" href="filer/DL_Logo.svg" type="image/svg">
</head>

<body>
    <h1>Hello this is kinda working...</h1>
    <div id="container"></div>
    <script src="/dist/bundle.js" type="text/javascript"></script>
    <!-- Resource jQuery -->
</body>

</html>

我没有控制台错误,网络选项卡显示它已加载捆绑包JS文件。

我认为问题出在Webpack捆绑包配置或Express上。

我解决了 问题不在于服务器端,而在于反应路由。 我在我的react router exakt路径上安装了该组件,因此该组件从不安装任何其他URL。 希望这对我的情况有所帮助

暂无
暂无

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

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