Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/angular/src/app/inertia/entities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InjectionToken, Type } from '@angular/core';

export const INERTIA_PAGES = new InjectionToken<InertiaPage>('INERTIA_PAGES');
export const INERTIA_PAGES = new InjectionToken<InertiaPage[]>('INERTIA_PAGES');

export enum InertiaMetadata {
component = 'inertia:component'
Expand Down
28 changes: 25 additions & 3 deletions resources/angular/src/app/inertia/inertia-link.directive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Directive, HostListener, Input } from '@angular/core';
import { Directive, HostListener, Input, ElementRef } from '@angular/core';
import { router } from "@inertiajs/core";

@Directive({
Expand All @@ -8,7 +8,29 @@ export class InertiaLinkDirective {

@Input('inertiaLink') href = '';

@HostListener('click') onClick() {
router.get(this.href);
constructor(private el: ElementRef<HTMLElement>) {}

@HostListener('click', ['$event'])
onClick(event: MouseEvent) {
// Only handle primary (usually left) button
if (event.button !== 0) {
return;
}

// Respect modifier keys so users can open in new tab/window
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
return;
}

// If no explicit href input, try to read from host element (e.g. <a href="...">)
const href = this.href || (this.el.nativeElement.getAttribute && this.el.nativeElement.getAttribute('href')) || '';

if (!href) {
return;
}

// Prevent native navigation and use Inertia router
event.preventDefault();
router.get(href);
}
}
3 changes: 3 additions & 0 deletions resources/angular/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Ensure reflect-metadata is loaded before decorators are evaluated.
import 'reflect-metadata';

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
Expand Down