fix: React Refresh has trouble inferring router exports
This commit is contained in:
parent
c5befc3965
commit
07b64dc217
|
@ -1,4 +1,4 @@
|
||||||
import {resolve} from 'path';
|
import {join, resolve} from 'path';
|
||||||
|
|
||||||
import {register} from 'react-refresh/runtime';
|
import {register} from 'react-refresh/runtime';
|
||||||
|
|
||||||
|
@ -83,8 +83,7 @@ export async function createRoutesFromFiletree({importer, paths, resolver}) {
|
||||||
const last = parts[i + 1];
|
const last = parts[i + 1];
|
||||||
// Non-index is a sibling, create if necessary.
|
// Non-index is a sibling, create if necessary.
|
||||||
if ('index' !== last) {
|
if ('index' !== last) {
|
||||||
const offset = '/' === parts[i] ? 1 : 0;
|
const nestedPath = join(...segments.slice(i));
|
||||||
const nestedPath = segments.slice(i + offset).join('/');
|
|
||||||
route = walk.find(({path}) => nestedPath === path);
|
route = walk.find(({path}) => nestedPath === path);
|
||||||
if (!route) {
|
if (!route) {
|
||||||
route = {path: nestedPath};
|
route = {path: nestedPath};
|
||||||
|
|
|
@ -5,7 +5,7 @@ import {createRoutesFromContext} from '@flecks/react/router';
|
||||||
it('does not nest siblings', async () => {
|
it('does not nest siblings', async () => {
|
||||||
const routes = await createRoutesFromContext(require.context('./filetree/siblings'));
|
const routes = await createRoutesFromContext(require.context('./filetree/siblings'));
|
||||||
expect(routes)
|
expect(routes)
|
||||||
.to.deep.equal([{path: '/', name: 'index'}, {path: 'test', name: 'sibling'}]);
|
.to.deep.equal([{path: '/', name: 'index'}, {path: '/test', name: 'sibling'}]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does nest siblings under parent', async () => {
|
it('does nest siblings under parent', async () => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user