链接在新标签或新窗口中不起作用

问题描述

我可以从基本URL浏览所有链接页面或组件,但是无法在新标签中打开诸如“ http:// localhost:4200 / home / dashboard”之类的URL。它显示空白页。

注意:即使刷新页面,它也显示空白

import { NgModule } from '@angular/core';
import { Routes,RouterModule } from '@angular/router';
import { ErrorsComponent } from './errors/errors.component';
import { FullComponent } from './layouts/full/full.component';
import { LoginComponent } from './login/login.component';
import { SignupComponent } from './signup/signup.component';
import { WelcomeComponent } from './welcome/welcome.component';

export const Approutes: Routes = [
    {
        path: 'home',component: FullComponent,children: [
            { path: '',redirectTo: 'dashboard',pathMatch: 'full' },{
                path: 'dashboard',loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardModule)
            },{
                path: 'component',loadChildren: () => import('./component/component.module').then(m => m.ComponentsModule)
            }
        ]
    },{
        path: 'login',component: LoginComponent,},{
        path: 'signup',component: SignupComponent,{
        path: '',component: WelcomeComponent,pathMatch: 'full'
    },{
        path: '**',redirectTo: '/',}
];

解决方法

感谢jonrsharpe, 在文档中,它说-

路由的应用程序应支持“深层链接”。深层链接是一个URL 指定应用程序内部组件的路径。例如, http://www.example.com/heroes/42是指向英雄详细信息页面的深层链接 显示ID为42的英雄。

当用户从导航栏中导航到该URL时没有问题。 正在运行的客户端。 Angular路由器解释URL并路由到 该页面和英雄。

但是单击电子邮件中的链接,然后在浏览器地址中输入 栏,或者只是在英雄详细信息页面上刷新浏览器- 所有这些操作均由浏览器本身在 正在运行的应用程序。浏览器直接向服务器发出请求 网址,绕过路由器。

静态服务器在收到静态服务器时通常会返回index.html 请求http://www.example.com/。但它拒绝 http://www.example.com/heroes/42并返回404-Not Found错误 除非它配置为返回index.html。

所以我的问题根本不是问题。