从 Angular 9 中的路由路径中删除 HashTag
Remove HashTag from route path in Angular 9
路由模块具有通用的标签表示 { useHash: true }
,没有特定路径。
{ path: 'documentDelivered', component: DocumentDeliveredComponent },
{ path: 'health', component: MonitoringComponent },
@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true })],
http://localhost:4200/#/documentDelivered
I need to remove hashtag(#) only for below "health" path.
我实施的步骤并且运行良好
从路由器模块中删除 useHash: true
,默认为 false。
在索引页的基本 href 中添加 /
斜杠
现在它在开发环境中工作正常。
对于产品,我们需要在 (.htaccess) 文件中添加规则。
修复了限制重定向到路由器中的兄弟和子路径的问题。
基本上问题出现在产品中而不是开发中。
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirection of requests to index.html
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) index.html [NC,L]
</IfModule>
参考:https://julianpoemp.github.io/ngx-htaccess-generator/#/generator
干杯:)
路由模块具有通用的标签表示 { useHash: true }
,没有特定路径。
{ path: 'documentDelivered', component: DocumentDeliveredComponent },
{ path: 'health', component: MonitoringComponent },
@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true })],
http://localhost:4200/#/documentDelivered
I need to remove hashtag(#) only for below "health" path.
我实施的步骤并且运行良好
从路由器模块中删除
useHash: true
,默认为 false。在索引页的基本 href 中添加
/
斜杠
现在它在开发环境中工作正常。
对于产品,我们需要在 (.htaccess) 文件中添加规则。
修复了限制重定向到路由器中的兄弟和子路径的问题。 基本上问题出现在产品中而不是开发中。
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirection of requests to index.html
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) index.html [NC,L]
</IfModule>
参考:https://julianpoemp.github.io/ngx-htaccess-generator/#/generator
干杯:)