Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Skip router render meanwhile there is no outlet #179

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
24 changes: 14 additions & 10 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ import { routes } from './routes.js';

const router = new Router();

router.setRoutes([
// Redirect to URL without trailing slash
{
path: '(.*)/',
action: (context, commands) => {
const newPath = context.pathname.slice(0, -1);
return commands.redirect(newPath);
router.setRoutes(
[
// Redirect to URL without trailing slash
{
path: '(.*)/',
action: (context, commands) => {
const newPath = context.pathname.slice(0, -1);
return commands.redirect(newPath);
},
},
},
...routes,
]);
...routes,
],
true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First we skip the router render.

);

export const attachRouter = (outlet: HTMLElement) => {
router.setOutlet(outlet);
router.render(window.location, true);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we force the first render when attach the router.

};

export const urlForName = (name: string, params?: Params) => {
Expand Down