mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-06-18 07:28:54 +08:00
fix: return '/' for empty paths
This commit is contained in:
@@ -489,3 +489,31 @@ it('handles empty path at the end', () => {
|
||||
expect(getPathFromState(state, config)).toBe(path);
|
||||
expect(getPathFromState(getStateFromPath(path, config), config)).toBe(path);
|
||||
});
|
||||
|
||||
it('returns "/" for empty path', () => {
|
||||
const config = {
|
||||
Foo: {
|
||||
path: '',
|
||||
screens: {
|
||||
Bar: '',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const state = {
|
||||
routes: [
|
||||
{
|
||||
name: 'Foo',
|
||||
state: {
|
||||
routes: [
|
||||
{
|
||||
name: 'Bar',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
expect(getPathFromState(state, config)).toBe('/');
|
||||
});
|
||||
|
||||
@@ -158,6 +158,10 @@ export default function getPathFromState(
|
||||
current = route.state;
|
||||
}
|
||||
|
||||
path = path.slice(path.length - 1) === '/' ? path.slice(0, -1) : path;
|
||||
path =
|
||||
path !== '/' && path.slice(path.length - 1) === '/'
|
||||
? path.slice(0, -1)
|
||||
: path;
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user