.htaccess 刷新时页面返回空白,Angular 12网站版本上出现MIME错误

bvhaajcl  于 2023-03-09  发布在  Angular
关注(0)|答案(1)|浏览(130)

我有一个问题,我的寻呼机上的一个Angular 12网站项目,我做了。
刷新页面时www.project.com/media/690-690是介质的ID或任何其他ID-返回空白,并且出现以下错误

1934:1          GET http://localhost:8100/user/runtime.js net::ERR_ABORTED 404 (Not Found)
11Refused to apply style from '<URL>' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
1934:1          GET http://localhost:8100/user/polyfills.js net::ERR_ABORTED 404 (Not Found)
1934:1          GET http://localhost:8100/user/vendor.js net::ERR_ABORTED 404 (Not Found)
1934:1          GET http://localhost:8100/user/main.js net::ERR_ABORTED 404 (Not Found)
1934:51          GET http://localhost:8100/user/capacitor.js net::ERR_ABORTED 404 (Not Found)
1934:1          GET http://localhost:8100/user/styles.js 404 (Not Found)
1934:46 Refused to execute script from 'http://localhost:8100/user/styles.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
1934:1 Refused to execute script from 'http://localhost:8100/user/capacitor.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

如果我刷新页面www.project.com/media(没有任何id),那么页面刷新正常。所以,问题出在id上。
app-routing.module.ts

import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
import { AuthGuard } from "./guards/auth.guard";

const routes: Routes = [
  { path: '', redirectTo: 'welcome', pathMatch: 'full'},
//  { path: 'welcome', loadChildren: () => import('./pages/welcome/welcome.module').then(m => m.WelcomePageModule), canActivate: [AuthGuard] },
  { path: 'welcome', loadChildren: () => import('./pages/welcome/welcome.module').then(m => m.WelcomePageModule) 
  }, 
  { path: 'user/:id', loadChildren: () => import('./pages/user/user.module').then(m => m.UserPageModule) },
  { path: 'media/:id', loadChildren: () => import('./pages/media/media.module').then(m => m.MediaPageModule) },

用户也是如此
从另一个组件到媒体页面的链接

goMedia(media: any) {
    media = media;
    this.userData.mediaViewed(media).pipe(
      map((data: any) => {
        if (data.success) {
          const navigationExtras: NavigationExtras = {
            state: {
              media: media
            }
          };
          this.router.navigate(['media/' + media.msg_id], navigationExtras);
        }
      })
    ).subscribe()
  }

媒体页面. ts

ngOnInit() {
    this.activateRoute.paramMap.subscribe(params => {

      var id = params.get('msg_id');

      console.log(id);

    });
  }

我的服务器管理员说这是我的错,服务器允许CSS或JavaScript的所有MIME类型。
有人帮忙吗?

vfhzx4xs

vfhzx4xs1#

MIME类型错误是因为404(text/html)响应试图被读取为JavaScript(application/javascript)文件-实际上不是。
404响应似乎是因为您正在请求URL /user/,并且您在HTML源代码中使用了相对URL,因此浏览器(例如)请求/user/assets/icon/favicon.png而不是/assets/icon/favicon.png,我认为这是目的。

<base href="./" />

在这里使用 relative BASE href实际上没有意义。这应该是所有其他相对URL相对的URL。例如,如果它们应该相对于根/index.html文档:

<base href="https://example.com/index.html">

base元素是一个“void元素”,所以应该有 no(self)结束标记。
你也许可以通过简单地删除点来摆脱。例如href="/"

相关问题