Angular 在IIS上以JS或PNG作为路由子字符串的角度路由
我在IIS上运行一个有角度的网站 我定义了路线并使用了网络配置,几乎所有的东西都很好:Angular 在IIS上以JS或PNG作为路由子字符串的角度路由,angular,iis,routes,web-config,Angular,Iis,Routes,Web Config,我在IIS上运行一个有角度的网站 我定义了路线并使用了网络配置,几乎所有的东西都很好: export const routes: Routes = [ { path: '', component: PageMainComponent }, { path: 'singlekey', component: PageSingleKeyComponent }, { path: 'singlekey/:lizKey', component: PageSingleKeyComponent },
export const routes: Routes = [
{ path: '', component: PageMainComponent },
{ path: 'singlekey', component: PageSingleKeyComponent },
{ path: 'singlekey/:lizKey', component: PageSingleKeyComponent },
{ path: '**', redirectTo: '' },
];
web.config:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="SPA" stopProcessing="true">
<match url="^(?!.*(.js|.css|.png|.jpg|.ico|.svg)).*$" />
<conditions logicalGrouping="MatchAll">
</conditions>
<action type="Rewrite" url="/" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
如果我使用如下URL:
https://domain/singlekey/DE1234
DE1234作为参数键正确传递给页面/组件
但是如果路由的最后一部分包含PNG或JS,我会从IIS中得到一个404错误:
https://domain/singlekey/JS1234
这是我必须在web.config中澄清的还是我必须在angular的路由中配置的?请尝试将.js更改为.js,将.css更改为.css?什么?区别在哪里?@Konrad。被视为任何字符和\。只是正则表达式中的一个点。您可以在IIS“测试模式”中测试它。顶部。工作!用\。css