【问题标题】:Links are not working in new tab or new window链接在新选项卡或新窗口中不起作用
【发布时间】:2021-01-03 06:41:37
【问题描述】:

我可以从基本 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: '/',
    }
];

【问题讨论】:

  • 这可能与 Angular 无关,并且与您的服务器配置有关,请参阅 angular.io/guide/deployment#server-configuration,但请进行一些调试 - 为什么页面是空白的?控制台中的错误?网络标签中出现意外的请求或响应?

标签: angular typescript angular-router


【解决方案1】:

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

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

当用户从一个 运行客户端。 Angular 路由器解释 URL 和路由到 那个页面和英雄。

但是点击电子邮件中的链接,在浏览器地址中输入 栏,或者只是在英雄详情页面上刷新浏览器—— 所有这些操作都由浏览器本身处理,在 运行应用程序。浏览器直接向服务器发出请求 对于该 URL,绕过路由器。

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

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

【讨论】:

    猜你喜欢
    • 2023-04-04
    • 2012-06-22
    • 1970-01-01
    • 2013-03-11
    • 2010-09-12
    • 2013-03-22
    • 2012-01-22
    相关资源
    最近更新 更多