简体   繁体   English

routerLink无法与AOT构建配合使用

[英]routerLink not working with AOT build

The routerLink works fine when I do a normal JIT build. 当我进行常规的JIT构建时,routerLink可以正常工作。 But when I try to do an AOT build router link does not redirect to the specified route. 但是,当我尝试执行AOT构建路由器链接时,不会将其重定向到指定的路由。

My html code 我的html代码

<ul id="submenu" class="lista-menu aln-centro">
     <li><a 
        routerLinkActive='active'
        routerLink='home'
     >Home</a></li>
     <li><a 
        routerLinkActive='active'
        routerLink='products'
    >Products</a></li>
    <li><a 
        routerLinkActive='active'
        routerLink='about'
    >About</a></li>
    <li><a 
        routerLinkActive='active'
        routerLink='contacts'
    >Contacts</a></li>
</ul>

Since the routing is working in the JIT build therefore I think either I have missed something in my webpack build process or this is a bug in the the @angular/router module, more likely the first one. 由于路由在JIT构建中正常工作,因此我认为或者我错过了Webpack构建过程中的某些内容,或者这是@angular/router模块中的错误,很有可能是第一个错误。

Link to git repo with the complete code: https://github.com/rachitbhasin/ng2-webpack-aot 使用完整的代码链接到git repo: https : //github.com/rachitbhasin/ng2-webpack-aot

Node version: 6.4.0 or greater. 节点版本:6.4.0或更高。

Install dependencies: npm install 安装依赖项: npm install

Run DEV/JIT build: npm run start 运行DEV / JIT构建: npm run start

Run AOT build: npm run build 运行AOT构建: npm run build

Run server after AOT build: npm run server 在AOT构建之后运行服务器: npm run server

Thanks in advance. 提前致谢。

The cause is not the Angular router forwarding but the http server, which can not give a suitable response for the request. 原因不是Angular路由器转发,而是HTTP服务器,它无法为请求提供适当的响应。

Simply configure your http server to always return the index.html file. 只需将http服务器配置为始终返回index.html文件。

See this example with Express . 参见Express的示例。

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

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